我想设置一个条件,它将在swift中更改视图中特定标签的位置。我想我会将标签位置的变化放在viewDidLoad()
中,但是如果我根据条件移动标签的约束,那么它(在重新加载时)是否具有位置中的标签/在故事板上手动设置约束?或者我需要将该位置编码回来吗?
if condition x{
//move label position
} else{
//keep the position set in storyboard, even upon reload
}
这可能吗?
答案 0 :(得分:-1)
///I have created the button & label on storyboard. And changing the position of label when button is clicked. I have added the constraint to the label on storyboard & created the outlet of top constraint.
var flag = true
@IBOutlet weak var UiLblConstraintTop: NSLayoutConstraint!
@IBAction func ChangePositionOfLabel(sender: UIButton) {
if flag{
self.UiLblConstraintTop.constant = 300
}
else{
self.UiLblConstraintTop.constant = 50
}
flag = !flag
self.view.layoutIfNeeded()
}