-(void)createBookingMarksWithArray:(NSArray *)booksArray
{
//booksArray 是标签数组
UILabel *titleLB1=[[UILabel alloc]initWithFrame:CGRectMake(0, 130, DEF_SCREEN_WIDTH, 20)];
titleLB1.font=[UIFont fontWithName:@"Helvetica-Bold" size:15];
titleLB1.textAlignment=NSTextAlignmentCenter;
titleLB1.text=@"已有标签";
titleLB1.backgroundColor=[UIColor clearColor];
[self addSubview:titleLB1];
CGFloat allWidth=30;
static int j=0;
for (int i=0; i<booksArray.count; i++)
{
NSString *booking=[booksArray objectAtIndex:i];
//DEF_SCREEN_WIDTH 为屏幕宽度
if ((allWidth+5+booking.length*25)<DEF_SCREEN_WIDTH)
{
//NSLog(@"%f",allWidth);
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(allWidth+5, titleLB1.bottom+20+30*j,booking.length*25, 25)];
label.backgroundColor=[UIColor colorWithRed:0.64 green:0.64 blue:0.64 alpha:1];
label.text=booking;
label.layer.cornerRadius=6;
label.layer.masksToBounds = YES;
label.textAlignment=NSTextAlignmentCenter;
label.font=[UIFont systemFontOfSize:13];
label.textColor=[UIColor whiteColor];
UIFont *font = [UIFont fontWithName:@"Arial" size:18];
CGSize size = CGSizeMake(320,25);
CGSize labelsize = [booking sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
[label setFrame:CGRectMake(allWidth+5, titleLB1.bottom+20+30*j, labelsize.width, 25)];
[self addSubview:label];
allWidth=label.right+5;
//NSLog(@"%f",allWidth);
}
else
{
++j;
self.contentSize=CGSizeMake(DEF_SCREEN_WIDTH, 260+j*30);
allWidth=30;
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(allWidth+5, titleLB1.bottom+20+30*j,booking.length*25, 25)];
label.backgroundColor=[UIColor colorWithRed:0.64 green:0.64 blue:0.64 alpha:1];
label.text=booking;
label.layer.cornerRadius=6;
label.layer.masksToBounds = YES;
label.textAlignment=NSTextAlignmentCenter;
label.font=[UIFont systemFontOfSize:13];
label.textColor=[UIColor whiteColor];
UIFont *font = [UIFont fontWithName:@"Arial" size:18];
CGSize size = CGSizeMake(320,25);
CGSize labelsize = [booking sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
[label setFrame:CGRectMake(allWidth+5, titleLB1.bottom+20+30*j, labelsize.width, 25)];
[self addSubview:label];
allWidth=label.right+5;
}
}
}