UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 300, 50)];
label.text = @"斋堂岛-云共千帆舞, 浪淘万里沙。 万世基业在何方? 天高知帝家。一人既称孤, 何人敢道寡? 雄视秦王挥鞭处, 遍地英雄花。云共千帆舞, 浪淘万里沙。 万世基业在何方? 天高知帝家。一人既称孤, 何人敢道寡? 雄视秦王挥鞭处, 遍地英雄花。";
//清空背景颜色
label.backgroundColor = [UIColor clearColor];
//设置字体颜色为白色
label.textColor = [UIColor whiteColor];
//设置label的背景色为黑色
label.backgroundColor = [UIColor blackColor];
//文字居中显示
label.textAlignment = NSTextAlignmentLeft;
//自动折行设置
label.lineBreakMode = NSLineBreakByCharWrapping;
label.numberOfLines = 0;
//自适应高度
CGRect currentFrame = label.frame;
label.frame = CGRectMake(20, 100, 300,
currentFrame.size.height =[label.text boundingRectWithSize:
CGSizeMake(currentFrame.size.width, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:[NSDictionary dictionaryWithObjectsAndKeys:label.font,NSFontAttributeName, nil] context:nil].size.height);
[self.view addSubview:label];
效果: