[英]UIImageView and Auto Layout in Code
I'm trying to use programmatic visual constraints to display a label and a button next to one another. 我正在尝试使用程序化视觉约束来彼此相邻显示标签和按钮。 However, the
UIImageView
used as the button's background is making the intrinsic size of the button much too large. 但是,用作按钮背景的
UIImageView
会使按钮的固有尺寸太大。
I attempted to add a constraint that forces the height of the button to match the height of the label. 我试图添加一个约束,以强制按钮的高度与标签的高度匹配。 But I just got a super tall label instead of a smaller button.
但是我只是得到了一个超高的标签,而不是一个较小的按钮。
The following works for this: 为此,以下工作:
@"|-[titleLabel][refreshButton(==26)]"
@"|-[titleLabel][refreshButton(==26)]"
Add a constraint such that the height of the button is equal to its own (now explicit) width: 添加一个约束,使按钮的高度等于其自身的宽度(现在是显式的):
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:refreshButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:refreshButton attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f];
I would still prefer a solution that uses the label's height, instead of a fixed value. 我仍然希望使用标签高度而不是固定值的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.