Search code examples
macoscocoanssearchfield

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.


Solution

  • 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