gpt4 book ai didi

uiview - UIView 上的固定高度约束

转载 作者:行者123 更新时间:2023-12-04 11:09:36 28 4
gpt4 key购买 nike

我的布局中有一个 UIView 以便进行一些剪辑和分组,但是自动布局会在缩小时调整它的大小。我想给它一个固定的高度,但唯一的选择是设置顶部和底部空间。

有没有办法设置明确的高度约束?

最佳答案

我刚刚找到了这个答案( Auto-Layout Constraint: How to make a view maintains its width/height ratio when resized? )。这是我的实现的样子:

- (void)awakeFromNib
{
[super awakeFromNib];

NSLayoutConstraint *con1 = [NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:self.frame.size.height];
[self addConstraint:con1];
}

关于uiview - UIView 上的固定高度约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14248046/

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