当 UILabel 中的文本发生变化时如何重新绘制 UIView?
我有一个 UIView 的子类,其中有一个 UILabel 作为子视图添加到视图中。在 layoutSubviews 方法中,计算 UILabel 的位置和高度。我的问题是,当 UILabel 的文本发生变化时,应该重新计算这个高度。文本从 UIViewController 插入到标签中,因此视图不知道这种情况何时发生。
I've a subclass of UIView with a UILabel with is added as subview to the view. In the layoutSubviews method the position and height of the UILabel is calculated. My problem is, that this height should be recalculated, when the text of the UILabel changes. The text is inserted into the label from the UIViewController, so the view does not know when this happen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以子类化
UILabel
来覆盖setText:
,如下所示:You can subclass
UILabel
to overridesetText:
like this: