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)?
Asked
Active
Viewed 97 times
0
-
Which style and elements? – Willeke Feb 07 '21 at 22:44
-
As a graphical date picker. – Z S Feb 08 '21 at 05:07
-
Do you want to add padding or do you want to scale the date picker? – Willeke Feb 08 '21 at 08:01
-
Ideally both. Padding on the sides w.t.r. superview, and scaling the date picker (at least horizontally) as a view is resized. – Z S Feb 08 '21 at 22:19
1 Answers
0
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.

Willeke
- 14,578
- 4
- 19
- 47