CGSize size = [self.workModel.discriptionContent sizeWithFont:[UIFont systemFontOfSize:16.0f] constrainedToSize:CGSizeMake(widthScreen, 20000)];
CGFloat height = size.height;
NSLog(@"%f",height);
UILabel *contentLabel = [[UILabel alloc]init];
contentLabel.frame = CGRectMake(0, 85+30, widthScreen, height);
contentLabel.textColor = [UIColor blackColor];
contentLabel.numberOfLines = 0;
contentLabel.font = [UIFont systemFontOfSize:15];
contentLabel.text = self.workModel.discriptionContent;
contentLabel.textAlignment=NSTextAlignmentLeft;
contentLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[self.view addSubview:contentLabel];
欢迎使用优快云-markdown编辑器
最新推荐文章于 2021-01-07 23:01:28 发布
本文介绍了一种使用UILabel展示动态高度文本的方法。通过计算UILabel在指定字体大小和屏幕宽度约束下的实际高度,确保文本能够完全显示且不会超出屏幕范围。此外,还详细介绍了如何设置UILabel的属性以实现良好的阅读体验。
1189

被折叠的 条评论
为什么被折叠?



