label的width是固定的,输入不同的内容,比如“hello” 或者 “prevents me from using standard methods to resize the UILabel. I read on another post here that I'm supposed to use the function“ 后,label根据label.text来调整高度?
label的width是固定的,输入不同的内容,比如“hello” 或者 “prevents me from using standard methods to resize the UILabel. I read on another post here that I'm supposed to use the function“ 后,label根据label.text来调整高度?
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSString *, id> *)attributes context:(nullable NSStringDrawingContext *)context;
UILabel.numberOfLines = 0;
UILabel .lineBreakMode = NSLineBreakByCharWrapping;
[UILabel sizeToFit];
用自动布局的话高度不用设定,lable自动会计算高度。
要是没有layout的话,那就是自己计算高度了,label有个 sizeTofit 函数,返回的就是 size,你可以试一下。计算出来高度之后在给lable赋值高度就好了。
2 回答1.1k 阅读
1 回答1k 阅读✓ 已解决
1 回答2.7k 阅读
1 回答1.4k 阅读
1.7k 阅读
1 回答931 阅读
1 回答775 阅读
这个方法计算
size 传入你固定的宽度,高度传个最高
attr 传入你字体的大小
然后会返回一个 CGRect 给你
你自己去拿里面的 height 就可以了
再做不等高 cell 嘛?