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

浪子不回头ぞ 提交于 2021-01-21 09:15:29

问题


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];

enter image description here



来源:https://stackoverflow.com/questions/30287662/how-to-change-background-color-of-nssearchfield-like-in-messages-app-in-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!