以编程方式更改NSLayoutConstraint不起作用

时间:2014-05-07 20:19:10

标签: ios7 autolayout nslayoutconstraint nsautolayout

我在视图中有一个子视图,其中包括顶部,左侧,底部,右侧,宽度和高度。我也有IBOutlet用于身高限制。我想以编程方式更改高度约束,以便它增长并推送父视图。问题是,当我更改约束的常量时,它会推送父视图但不会扩展自身。但如果我在ui编辑器中这样做,它可以正常工作。

白色是我希望扩展的子视图 white one is subview which i want to expand

约束在这里

constraints are here

在约束设置enter image description here

之前

使用;

设置约束后
self.heightConst.constant = 300;

enter image description here

1 个答案:

答案 0 :(得分:0)

根据您的第二个屏幕截图,您尚未将您的属性(heightConst)分配给您的Interface Builder(.xib或.storyboard)

并确保您的财产有IBOutlet。 @property(非原子,弱)IBOutlet NSLayoutConstraint * heightConst;