iOS 在xib或者storyboard中添加AutoLayout后,在代码中修改AutoLayout约束条件

时间:2017-04-17 17:29:40   收藏:0   阅读:242

如果是viewControl则AutoLayout适配写在- (void)updateViewConstraints方法中修改约束;

如果是view则AutoLayout适配 则在- (void)updateConstraints方法中修改。

可以直接把视图的约束像拖控件一样拖成属性直接在下面的方法里更改即可

//遍历self.myView控件中的约束,找到NSLayoutAttributeHeight控件高度这个约束关系,然后修改

-(void)updateViewConstraints

{


    [superupdateViewConstraints];

    NSArray *constrains = self.myView.constraints;

    for(NSLayoutConstraint *constraintin constrains){

        if(constraint.firstAttribute ==NSLayoutAttributeHeight){

            constraint.constant = 50.0;

        }

    }

}


注意:方法中一定要加上[super updateViewConstraints] 这句话。否则会报错

原文:http://www.cnblogs.com/DevinSMR/p/6723727.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!