我想知道是否可以获得多线的高度UILabel
?我正在开发一个消息传递应用程序,并希望实现类似iPhone消息传递应用程序。计算UILabel的高度?
0
A
回答
1
您可以label.frame.size.height
0
1
你可能想的-[UILabel sizeThatFits:]
方法获得的财产。这就是你所做的。假设您的UILabel位于变量myLabel
中,并且您已将其宽度设置为任何您想要的值。
myLabel.text = @"This is my very long message which will probably need multiple lines to be displayed because it is very long.";
CGRect bounds = myLabel.bounds;
// Create a size that is the label's current width, and very very tall.
CGSize prototypeSize = CGSizeMake(bounds.size.width, MAXFLOAT);
// Ask myLabel how big it would be if it had to fit in prototypeSize.
// It will figure out where it would put line breaks in the text to
// fit prototypeSize.width.
CGSize fittedSize = [myLabel sizeThatFits:prototypeSize];
// Now update myLabel.bounds using the fitted height and its existing width.
myLabel.bounds = (CGRect){ bounds.origin, CGSizeMake(bounds.size.width, fittedSize.height) };
相关问题
- 1. UILabel高度计算
- 2. Monotouch - 计算UILabel高度
- 3. 如何计算UILabel的高度?
- 4. 如何在UILabel中设置不同类型的NSFontAttributeName来计算UILabel的高度?
- 5. UITableViewCell计算正确的高度,但UILabel不包装
- 6. iOS UILabel高度
- 7. 动态计算UITableViewCell中的UILabel宽度
- 8. 在UILabel中计算/伪造线高度变化
- 9. 计算器高度宽度
- 10. 计算UIScrollView的高度
- 11. 计算UITabBar的高度
- 12. JQuery:计算div的高度
- 13. 计算div的高度
- 14. 计算PivotItem的高度?
- 15. 调整UILabel的高度与tableViewCell高度的高度
- 16. 动力高度的UILabel
- 17. UITableViewCell里面的UILabel高度
- 18. 计算法线高度图
- 19. TCPDF计算细胞高度
- 20. swift中uiwebview高度计算
- 21. 高精度数值计算
- 22. C#高精度计算
- 23. 高度计算歧义
- 24. WinApi:计算ListView高度
- 25. 用LESS计算DIV高度
- 26. 如何计算div高度
- 27. IE不计算textarea高度与行高
- 28. 计算UILabel/UITableViewCell的多行文本高度:计算vs实际绘图时的结果不同
- 29. 计算UIBezierPath宽度和高度?
- 30. 从高度和角度计算斜边
谢谢! – 2011-12-19 21:45:16
@TusharChutani如果这个问题是你正在寻找的,请将它标记为已接受(左边的小标签) – MByD 2011-12-19 22:01:45