动态改变的UILabel宽度不自动布局工作 [英] Dynamically change UILabel width not work with autolayout
问题描述
我有一些code:
CGRect currentFrame = textLabel.frame;
CGSize max = CGSizeMake(textLabel.frame.size.width, 3000);
CGSize expected = [[textLabel text] sizeWithFont:textLabel.font constrainedToSize:max lineBreakMode:textLabel.lineBreakMode];
currentFrame.size.height = expected.height;
textLabel.frame = currentFrame;
expected.height = expected.height + 70;
[scrollView setContentSize:expected];
放在里面的UIScrollView为textLabel显示多行文本信息。
textLabel placed inside UIScrollView to display multiline text information.
在旧版本的应用程序,没有4英寸的屏幕支持,一切都很完美。
但现在,不幸的是,调整大小的UILabel不起作用。
In older version of application, without 4-inch screen support, everything was perfect. But now, unfortunately, resizing UILabel does not work.
也许,有人能指点我,我应该怎么改?
Maybe, somebody can advice me, what should I change?
感谢。
推荐答案
在使用自动版式,你不应该更新frame属性,而不是修改视图中的约束上。
When using AutoLayout you should not update the frame property, instead modify the contraints on a view.
在另一方面,你也可以让你自动版式的工作。确保标签的 numberOfLines
属性设置为0,高度约束的类型为大于或等于
( > =)。这样的布局将在标签上设置新的文本后自动更新。
On the other hand, you could also let AutoLayout work for you. Make sure the numberOfLines
property of the label is set to 0 and the height constraint is of type Greater Than or Equal
(>=). This way the layout will update automatically after setting new text on a label.
这篇关于动态改变的UILabel宽度不自动布局工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!