转自
http://blog.csdn.net/zaitianaoxiang/article/details/6743750
- 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];