Change position of IBOutlet in Swift
So, I have this button:
@IBOutlet var bouton: UIBarButtonItem!
And I want to change position
But the bud doesn't seem to have a position property like for SKSpriteNode
So, is there a way to change the position?
+3
Clément Bisaillon
source
to share
2 answers
If you want to programmatically change the position of any kind, you can use this:
button.frame.origin = CGPoint(x: 10, y: 10)
+12
Atomix
source
to share
You cannot set a button using myButton.frame.origin if you are using autoplay. Therefore, you must add constraints. For example:
let buttonConstraintY = NSLayoutConstraint(item: youButton, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 10)
self.view.addConstraint(buttonConstraintY)
+1
Illya Krit
source
to share