简体   繁体   English

如何使用自动布局根据其子视图调整父视图的高度?

[英]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;
  1. As your subViews change height change the value of the outlet 当您的子视图更改高度时,更改插座的值
self.viewHeight.constant = firstSubView.frame.size.height + secondSubView.frame.size.height;

Should work. 应该管用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用自动布局根据其子视图调整父视图的高度 - How to adjust the parent view's height according to its subviews using auto layout 如何根据子视图的高度设置堆栈视图的高度? - How to set stack view height according to its subviews height? 如何使UICollectionViewCell适合其子视图(使用自动布局) - How to make UICollectionViewCell fit its subviews (using Auto Layout) 如何在不添加/删除约束的情况下使用AutoLayout根据父级高度调整子视图高度的大小 - How to resize subviews height according to the parent height using AutoLayout without adding/removing constrains 在iOS中使用自动布局,如何将标签放置在其包含视图的高度的1/3处? - Using auto layout in iOS, how can I position a label at 1/3 of the height of its containing view? 视图的自动布局可隐藏子视图 - Auto Layout of view hides subviews 删除一个视图的布局约束,但保留其子视图? - Remove one view's layout constraints but keep its subviews'? 使用自动布局调整UINavigationBar的高度 - Adjust UINavigationBar height with Auto Layout 在Appcelerator iOS中父视图布局为垂直时调整高度 - Adjust height when parent view layout is vertical in appcelerator ios 使用自动布局时,在init上的子视图中查看控制器动画? - View controller animating in subviews on init when using auto layout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM