UILabel 自动换行 和支持换行符

NSString *str = @"你要放在label里的文本字符串  \n  换行符";
CGSize size = [str sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(width,10000.0f)lineBreakMode:UILineBreakModeWordWrap];

UILabel *lb = [[UILabel alloc]initWithFrame:CGRectMake(x,y,size.width,size.height)];
lb.numberOfLines = 0; // 最关键的一句
lb.text = str;
lb.font = [UIFont systemFontOfSize:14];
[self.view addSubview:lb];
[lb release];


你可能感兴趣的:(UILabel 自动换行 和支持换行符)