我们如何设置动态的前导和尾随约束,就像我们通过屏幕尺寸的百分比提供动态宽度和高度一样。
尝试这个
在你的视图控制器中添加以下属性
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cnstViewLeading;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cnstViewTrailing;
并且
使用方法如下:// replace value whatever you want with 0
self.cnstViewLeading.constant = 0;
self.cnstViewTrailing.constant = 0;
您可以创建NSLayoutConstraint
的输出口,并根据需要更新其常量。在更新其常量后,您需要调用view.layoutIfNeeded()
。
或者,您也可以使用乘数进行百分比布局。