代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//把<br!>换成
NSString *string=@"123<br!>456<br!>789";
NSString *newStr=[string stringByReplacingOccurrencesOfString:@"<br!>" withString:@"
"];
NSString *newNewStr=[newStr stringByReplacingOccurrencesOfString:@"
" withString:@"<br!>"];
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 100, 100, 200)];
label.backgroundColor=[UIColor redColor];
label.text=newNewStr;
//下面这个代码很重要,很重要的
label.numberOfLines=0;
[self.view addSubview:label];
}