我在我的应用程序中使用以下代码来获取 UILabel 的动态高度。
CGSize maximumLabelSize = CGSizeMake(231, FLT_MAX);
CGSize expectedLabelSize = [labelString
sizeWithFont:self.verbLabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:self.verbLabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = self.verbLabel.frame;
newFrame.size.height = expectedLabelSize.height;
self.verbLabel.frame = newFrame;
return newFrame;
我的labelString是如果你问一个有争议的公众人物怎么办?他/她可能会提出什么想法? 所以有时我能够显示整个字符串,但有时它只是剪切了一些文本。 我该如何解决这个问题...请帮助我,如果我做错了什么请告诉我。
最佳答案
将 numberOfLines 设置为 0 以允许任意数量的行。
label.numberOfLines = 0;
关于iphone - 具有动态高度的 UILabel 不适用于 iOS 中的相同字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16118837/