问题
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.
回答1:
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];
来源:https://stackoverflow.com/questions/30287662/how-to-change-background-color-of-nssearchfield-like-in-messages-app-in-os-x