这个问题有很多解决方案,但找不到不被弃用的解决方案。
我有一个UILabel
带模式的 WordWrap 和固定宽度,比如说 250。行设置为 0。
这是我尝试过的:
UILabel *contentLabel = (UILabel*)[contentView viewWithTag:10];
CGSize size = [contentLabel.text sizeWithFont:contentLabel.font forWidth:contentLabel.frame.size.width lineBreakMode:NSLineBreakByWordWrapping];
NSLog(@"Label's height is: %d", size.height);
height 参数的输出始终为 20(所以它就像一行),而 te text 的输出就像 30 行一样长。
我需要它用于 UIScrollView 的目的。