Resizable NSDatePicker with graphical mode

136 views Asked by At

I want to add a NSDatePicker in the sidebar of my app, to help select dates. The standard NSDatePicker only seems to come in a single size, and doesn't seem to be resizable. I've dropped the NSDatePicker component into a xib file, and added auto-layout constraints, but they don't seem to work. Is there a way to make them respond to auto-layout and be resizable? Or should I be looking for 3rd-party frameworks to integrate with (if so, any recommendations)?

1

There are 1 answers

0
Willeke On

Wrap the date picker in a superview. Set the bounds of the superview and the date picker will stretch.

class MyScaledView: NSView {

    @IBOutlet weak var wrappedSubView: NSView! // date picker
    
    override func layout() {
        super.layout()
        bounds = wrappedSubView.frame
    }
    
}

Constrain the location of the date picker but not its size. For example add constraints for leading and bottom space.