2015-01-16 106 views
1

请帮我解决问题。 我有创建复选框的func。在这个功能我增加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里面,并用新的高度复选框(注:在Interface Builder具有高度1.0默认) 但其他UIView位于myView下方的站点仍然站在他的位置。 如何更新myView的高度约束?或者,也许创建复选框时自动调整它?

谢谢大家!

+0

为您创建的约束一个IBOutlet,并设置你的'constraint.constant'是任何新的高度应 – Ian

+0

日Thnx!它的工作原理!) –

+0

你能包含更多的代码吗? – Esqarrouth

回答

0

为了解决这个问题,拖动约束在Interface Builder上您的课,让一个IBOutlet。

@IBOutlet weak var heightConstraint: NSLayoutConstraint! 

然后将其设置constraint.constant像这样:

heightConstraint.constant = 50