gpt4 book ai didi

ios - UILabel 自动布局宽度问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:44:54 24 4
gpt4 key购买 nike

所以我正在尝试对单元格内容 View 使用自动布局以获得正确的布局。所以我的问题是我有一个 UILabel 会根据其文本更改其大小,并且我还有一个 UIView 作为带有圆角的标签的背景 View 。所以我的问题是,如何强制此 UIView 的 宽度比 UILabel 宽 10 点。我设法使它具有相同的宽度,但我如何才能强制它始终保持一定的宽度?

提前致谢!

最佳答案

NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:yourLabel
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:yourLabel.superview
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:10]; // <-- this
[yourLabel.superview addConstraint:widthConstraint];

关于ios - UILabel 自动布局宽度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19767951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com