Search code examples
swiftnsbutton

Move NSButton swift


I have a NSButton named round, and I need to change its position according to the previous position, e.g. move it 100 pixels to the right. How to do that? I'm new to swift, so any help will be appreciated


Solution

  • You need to edit the frame of the button, basically changing the x coordinate with 100 pixels to the right, that means increasing it by 100. See the code below

    var button  = NSButton(frame: NSRect(x: 0, y: 0, width: 100, height: 50));
    var frame = button.frame
    frame.origin.x += 100
    button.frame = frame