Search code examples
cocoaposition

How would I go about changing to (x,y) position of an object


I'm going to try to keep this relatively simple. I have a NSImageView, and I would like to change it's (x,y) position on the screen programmatically.

How would I go about doing this?


Solution

  • If you add one programmatically, make sure you have translatesAutoresizingMaskIntoConstraints set to false, then set the frame of the NSImageView using the frame property

    imageView.frame = NSMakeRect(x, y, w, h);