【发布时间】:2015-05-12 07:57:45
【问题描述】:
我在UITableViewCell 中有UILabel,其相邻子视图为UIControlSwitch。当UIControlSwitch 被隐藏时,UILabel's 的宽度预计会增加。下面是我的自定义类实现:
- (void)setBounds:(CGRect)bounds
{
[super setBounds:bounds];
self.contentView.frame = self.bounds;
}
- (void)layoutSubviews
{
[super layoutSubviews];
[self.contentView updateConstraintsIfNeeded];
[self.contentView layoutIfNeeded];
self.numberLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.numberLabel.frame);
self.quoteLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.quoteLabel.frame);
}
@end
我已经上传了一个示例code 来解释故事板上的约束。
UILabel's 宽度没有变化。如果我在UILabel 和UIControlSwitch 之间设置一个尾随空格,则控件部分隐藏在屏幕边界之外。因此UILabel 的约束在超级视图而不是UIControlSwitch 有尾随空间。
【问题讨论】:
-
你已经为UILabel添加了约束-移除水平空间约束并尝试。
标签: ios uitableview autolayout uilabel