Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change background color of NSSearchField (like in Messages app in OS X)

I need to get this appearance of NSSearchField

But it seems to be impossible to set backgroundColor with standard methods of Interface Builder. How i can achieve this? Subclassing NSSearchField and NSSearchFieldCell didn't help, because i loose all animations (when you click on search field and icon+text sliding to left) when implementing my own draw methods.

like image 220
surfrider Avatar asked Feb 10 '23 02:02

surfrider


1 Answers

What your screenshot shows is just the standard look of NSSearchField when being placed under an NSVisualEffectView. That is, the search field will automatically get the look above when it's a subview of NSVisualEffectView (with the material of NSVisualEffectMaterialLight).

However, if you want this appearance without NSVisualEffectView, you can manually set its appearance:

searchField.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight];

enter image description here

like image 173
Renfei Song Avatar answered May 22 '23 05:05

Renfei Song