4

So i have this button:

@IBOutlet var bouton: UIBarButtonItem!

And i want to change is position

But the buton doesn't seems to have a position property like for SKSpriteNode

So is there a way to change is position ?

Clément Bisaillon
  • 5,037
  • 8
  • 32
  • 53

2 Answers2

18

If you want to programmatically change the position of any view, you can use this:

button.frame.origin = CGPoint(x: 10, y: 10)
Atomix
  • 13,427
  • 9
  • 38
  • 46
1

You can't set the button with myButton.frame.origin if you are using autolayout. So 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)

Illya Krit
  • 925
  • 1
  • 8
  • 9