CGFloat width = self.view.frame.size.width - 40; NSString * string = @"还记得你说家是唯一的城堡随着稻香河流继续奔跑微微笑 小时候的梦我知道不要哭让萤火虫带著你逃跑乡间的歌谣永远的依靠回家吧 回到最初的sdvsldfjnwefqej;wlednef,sbf.s,bfbkj.fejwfwfkjwjkfwefbwejfbwkjeb美好 还记得你说家是唯一的城堡随着稻还记得你说家是唯一的城堡随着稻还记得你说家是唯一的城堡随着稻还记得你说家是唯一的城堡随着稻还记得你说家是唯一的城堡随着稻还你说家是唯一的城堡随着稻还记得你说家是唯一的城堡随着稻还记得你说家"; NSMutableParagraphStyle * paragraph = [[NSMutableParagraphStyle alloc] init];// paragraph.lineSpacing = 10; NSDictionary * dict = @{NSFontAttributeName:[UIFont systemFontOfSize:30], NSParagraphStyleAttributeName:paragraph}; NSAttributedString * attribute = [[NSAttributedString alloc] initWithString:string attributes:dict]; //一定要先确定宽度,再根据宽度和字体计算size CGSize size = [string boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size; UILabel * label = [[UILabel alloc] init]; label.bounds = CGRectMake(0, 0, size.width, size.height); label.center = self.view.center; label.numberOfLines = 0; label.attributedText = attribute; label.backgroundColor = [UIColor yellowColor]; [self.view addSubview:label];