Question

I have a NSSearchField and I want to change its background color but i am not able to do it i tried out few things:

1) I tried to set DrawBackground TRUE and then setBackgroundColor but the value of DrawBackGround is always False either I try to set it trough code or Nib.(i don't know why?)

2)I tried out setting NSText's BackgroundColor but it is not looking good because it is not covering whole NSSearchField the extreme corners where the small search icon and cancel icon is present are left uncolored.

3)I want the searchField to have the color of the view it is lying so i decreased the alpha value of the searchField which looks good but the alpha value of text is also decreased so is there any way to make text's alpha value to remain always 1.

Thanks :)

Was it helpful?

Solution

NSSearchField is extension of NSTextField, NSTextField again extension of NSView,

Not sure, but its possible to make a custom clas and overwrite drawRect function and paint with the background color.

OTHER TIPS

If you look at the documentation, Apple prevents background color rendering for rounded-rectangle fields:

"In order to prevent inconsistent rendering, background color rendering is disabled for rounded-bezel text fields."

https://developer.apple.com/library/prerelease/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextField_Class/#//apple_ref/occ/instm/NSTextField/setDrawsBackground:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top