0

I've got a view and I'd like to add a check box to it under program control (no .xib file). Here is the code I'm trying, but I get no checkbox on the screen (it does draw everything else just fine in the view). Am I missing something?

Early in the class:

var rodLimitsCB : NSButton?

inside viewWillMoveToWindow:

    if showRodLimits && rodLimitsCB == nil {

        rodLimitsCB = NSButton(frame: NSRect(x: self.frame.origin.x+100, y: self.frame.origin.x+100, width: 30, height: 30))
        rodLimitsCB!.setButtonType( .SwitchButton )
        rodLimitsCB!.title = "Rod Limits"
        self.addSubview( rodLimitsCB! )
    }

Any pointers would be appreciated.

rawhide
  • 49
  • 4
  • 2
    Did you debug your code? and checked if your code is fire or not? – Dharmesh Kheni Aug 07 '16 at 18:12
  • Yup, the code is being called (checked with NSLog and I also set a breakpoint to verify that the appropriate parameters are being passed. – rawhide Aug 07 '16 at 21:58
  • I think your issue might be setting the frame of the button. i.e its off screen. "Core Graphics and UIKit use flipped co-ordinates (origin upper-left, positive y going down), whereas AppKit uses unflipped co-ordinates (origin lower-left, positive y going up)." http://stackoverflow.com/a/2151786/1186243 – sbarow Aug 07 '16 at 22:23
  • Changed it to `self.view.addSubview...` and that worked. Coordinates were fine. – rawhide Aug 08 '16 at 01:03

0 Answers0