更新约束

时间:2015-01-16 06:01:53

标签: ios swift

请帮我解决问题。 我有一个创建复选框的功能。在此功能中,我每次增加UIVIew的高度:

self.myView.addSubview(MyCheckbox)
myFrame.origin.y += myFrame.size.height. // This is the Y position of new checkbox. I.m creating a frame with checkbox and it's title inside. It's height depends on checkbox picture height.
self.myView.frame = CGRectMake(self.myView.frame.origin.x, self.myView.frame.origin.y, self.myView.frame.size.width, myFrame.origin.y) // And this is the updated frame with new Height.

在这种情况下,我有myView里面有复选框并且有新的高度(注意:它在界面构建器中默认高度为1.0) 但位于myView下方的其他UIView仍然站在他的位置。 如何更新myView的高度约束?或者在我创建复选框时自动调整它?

感谢所有人!

1 个答案:

答案 0 :(得分:0)

要处理此问题,请将界面构建器中的约束拖到您的类中并创建一个IBOutlet。

@IBOutlet weak var heightConstraint: NSLayoutConstraint!

然后通过设置constraint.constant来设置它:

heightConstraint.constant = 50
相关问题