在代码里更新autolayout布局

 1             //遍历view约束(高,宽)
 2             NSArray* constrains = self.View.constraints;
 3             for (NSLayoutConstraint* constraint in constrains) {
 4                 if (constraint.firstAttribute == NSLayoutAttributeHeight) {
 5                     //宽高的值
 6                     constraint.constant = 45.0;
 7                 }
 8             }
 9             
10            //遍历view约束,找到属于子view的约束
11             NSArray* constrains2 = self.view.constraints;
12             for (NSLayoutConstraint* constraint in constrains2) {
13                 if (constraint.secondItem == self.table) {
14                     //底部距离
15                     if (constraint.firstAttribute == NSLayoutAttributeBottom) {
16                         constraint.constant = 0.0;
17                         
18                     }
19                 }
20             }            

内容来自网络,并部分修改,非个人原创。

posted @ 2015-04-21 16:43  王权伟  阅读(250)  评论(0编辑  收藏  举报