David Seek
David Seek

Reputation: 17132

Swift / IBAction / CGRect on UIView.label

I want a top bar (UIView) to move as soon as a button is pressed.

@IBAction func displayOptions(sender: AnyObject) {

self.topBar.frame = CGRect(x: 100, y: 100, width: self.topBar.frame.size.width, height: self.topBar.frame.size.height)

}

Is not working. The UIView doesn't move.

I have tryed to set the original.x/y in the viewDidLoad, but it didn't changed anything.

override func viewDidLoad() {

    var xvalue = self.topBar.frame.origin.x
    var yvalue = self.topBar.frame.origin.y

    xvalue = 0
    yvalue = 0

    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

Help is very appreciated.

enter image description here

Upvotes: 1

Views: 257

Answers (1)

karthik
karthik

Reputation: 1281

You should change the constraints if you are working with auto layout rather than changing the frame.

Upvotes: 1

Related Questions