陈斌彬的技术博客

Stay foolish,stay hungry

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];