【问题标题】:Dynamically change UILabel width not work with autolayout动态更改 UILabel 宽度不适用于自动布局
【发布时间】:2013-01-21 12:28:59
【问题描述】:

我有一些代码:

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];

textLabel 放置在 UIScrollView 内,用于显示多行文本信息。

在旧版本的应用程序中,没有 4 英寸屏幕支持,一切都很完美。 但不幸的是,现在调整 UILabel 的大小不起作用。

也许,有人可以建议我,我应该改变什么?

谢谢。

【问题讨论】:

  • 为什么不用UITextField 控件来代替?

标签: ios autolayout


【解决方案1】:

使用 AutoLayout 时,您不应更新 frame 属性,而应修改视图上的约束。

另一方面,您也可以让 AutoLayout 为您工作。确保标签的numberOfLines 属性设置为0,并且高度约束的类型为Greater Than or Equal (>=)。这样,在标签上设置新文本后,布局将自动更新。

【讨论】:

  • 非常有帮助!谢谢!
  • 这对我有用,除了 Truncate Tail 不再工作?
猜你喜欢
  • 1970-01-01
  • 2014-01-14
  • 1970-01-01
  • 2015-08-30
  • 2016-08-01
  • 2013-04-07
  • 1970-01-01
  • 2015-11-18
  • 2013-11-30
相关资源
最近更新 更多