1

I am subclassing NSDatePicker to implement calendar widget. I am able to change text color by setting textColor property of NSDatePicker but when I click on any field of NSDatePicker like Month/Year/Day the default color is somewhat blue.

I want to change highlight color to some custom color but I am not able to do that. I tried overriding highlightColorWithFrame:inView: and highlight:withFrame:inView: but no effect. This is how it looks at present

enter image description here

Ankur
  • 3,584
  • 1
  • 24
  • 32

1 Answers1

0

I would not recommend to change the selection color of a control since maxOS Mojave will allow the user to customise the Accent color in system preferences.

If ever you are still looking for customisation you must customise the drawing of the NSDatePickerCell and not of the control itself. I would try to overwrite

draw(withFrame cellFrame: NSRect, in controlView: NSView)

but for NSDatePickerCell it may be some more difficult since there are multiple datePicker elements.

Marc T.
  • 5,090
  • 1
  • 23
  • 40
  • Is this new in macOS Mojave or is this the same as changing the Highlight Color? – Willeke Jun 29 '18 at 10:04
  • Yes its new in Mojave. It is changing the Highlight Color as well the color of controls. I assume more user then before will customise the os. I have never changed the Highlight Color before but now I have set the Accent color to grey. – Marc T. Jun 30 '18 at 18:59
  • @MarcT. This is not working. Breakpoint is not hitting this method. – Ankur Jul 01 '18 at 07:46
  • @Ankur If you subclass NSDatePickerCell properly it will work. Check out this Git repository https://github.com/MarcTeichmann/macOS-Calendar-DatePicker/blob/master/macOS%20Calendar%20like%20DatePicker/CustomDatePickerCell.swift – Marc T. Jul 01 '18 at 08:10
  • @MarcT. I have subclassed NSDatePicker instead of NSDatePickerCell. So should I subclass NSDatePickerCell instead of NSDatePicker? – Ankur Jul 01 '18 at 08:26
  • Yes, its to subclass NSDatePickerCell. – Marc T. Jul 01 '18 at 08:28
  • @MarcT. Tried it. But it is actually highlighting complete NSDatePickerCell instead of a particular element like only date or month or year. – Ankur Jul 01 '18 at 10:48
  • @Ankur: As I mentioned in my answer it can be some difficult to make the custom cell drawing for NSDatePickerCell. You will have to find out which element is selected to draw the selection partial. – Marc T. Jul 02 '18 at 04:48