ios label尺寸_ios – UILabel文本不会使用自动布局自动调整大小

我试图实现一个受限制的UITableViewCell子类,一切都正常工作,除了UILabel.我设置的约束肯定是强制执行的,但是当限制冲突时,标签内的文本不会调整为较小的字体大小.相反,UILabel的高度被截断,并且字体保持相同的大小,这意味着字母在顶部和底部被切断.

有没有一些方法我必须调用,以使其工作?我认为自动布局会足够聪明,可以自动调整字体大小,所以我为什么会发生这样的事情.

相关代码:

self.label = [[UILabel alloc] initWithFrame:CGRectZero];

self.label.textColor = [UIColor whiteColor];

self.label.translatesAutoresizingMaskIntoConstraints = NO;

self.label.textAlignment = NSTextAlignmentCenter;

self.label.numberOfLines = 1;

[self.contentView addSubview:self.label];

NSLayoutConstraint *otherViewToLabelHorizontalConstraint = // Make sure that the label is always to the right of the other view.

[NSLayoutConstraint constraintWithItem:self.label

attribute:NSLayoutAttributeLeft

relatedBy:NSLayoutRelationGreaterThanOrEqual

toItem:self.otherView

attribute:NSLayoutAttributeRight

multiplier:1.0

constant:0.0];

NSLayoutConstraint *aTextFieldToLabelVerticalConstraint =

[NSLayoutConstraint constraintWithItem:self.label

attribute:NSLayoutAttributeTop

relatedBy:NSLayoutRelationGreaterThanOrEqual

toItem:self.aTextField

attribute:NSLayoutAttributeBottom

multiplier:1.0

constant:0.0];

基本上,这些约束意在强制执行其他view在左侧的单元格,aTextField位于同一y级别的otherView右侧,标签位于aTextField下方,在右侧的otherView底部.

像往常一样,感谢任何帮助.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值