[英]How to adjust the parent view's height according to its subviews using auto layout?
I have cutomized a view, whose subviews's height will dynamically change. 我已经对视图进行了裁剪,其子视图的高度将动态变化。 My intention is to let the view's height adjust to its subviews' height by using auto layout. 我的意图是通过使用自动布局使视图的高度调整为其子视图的高度。
One simple way to do it: 一种简单的方法:
1. Set the view's height constant in storyboard 1.在情节提要中设置视图的高度常数
2. Import that constraint as an outlet 2.将该约束导入为出口
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewHeight;
self.viewHeight.constant = firstSubView.frame.size.height + secondSubView.frame.size.height;
Should work. 应该管用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.