我想知道是否可以获得多线的高度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. UITableViewCell计算正确的高度,但UILabel不包装
- 3. 动态计算UITableViewCell中的UILabel宽度
- 4. 在UILabel中计算/伪造线高度变化
- 5. 计算器高度宽度
- 6. 计算UITabBar的高度
- 7. 计算div的高度
- 8. 计算UIScrollView的高度
- 9. UITableViewCell里面的UILabel高度
- 10. 动力高度的UILabel
- 11. 用LESS计算DIV高度
- 12. WinApi:计算ListView高度
- 13. swift中uiwebview高度计算
- 14. 高精度数值计算
- 15. 如何计算div高度
- 16. 计算UILabel/UITableViewCell的多行文本高度:计算vs实际绘图时的结果不同
- 17. 计算UIBezierPath宽度和高度?
- 18. 从高度和角度计算斜边
- 19. UILabel有最大高度吗?
- 20. 的Javascript/jQuery的高度计算
- 21. 计算包含HTML的NSAttributedString的高度
- 22. 计算我的UIWebView的高度?
- 23. 计算父元素的高度
- 24. 计算高度的问题ExpandableListView
- 25. F#计算三元节点的高度
- 26. 提高大块SumIfs的计算速度
- 27. 用文本计算div的高度
- 28. 如何计算B点的高度?
- 29. 计算AngularJS中DOM的动态高度
- 30. 如何计算树的高度
谢谢! – 2011-12-19 21:45:16
@TusharChutani如果这个问题是你正在寻找的,请将它标记为已接受(左边的小标签) – MByD 2011-12-19 22:01:45