问题描述
我需要获得NSSearchField的外观
I need to get this appearance of NSSearchField
但是用Interface Builder的标准方法设置backgroundColor似乎是不可能的.我怎样才能做到这一点?子类化NSSearchField和NSSearchFieldCell并没有帮助,因为在实现自己的draw方法时,我松开了所有动画(当您单击搜索字段并且icon + text向左滑动时).
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.
推荐答案
当置于 NSVisualEffectView
下时,您的屏幕快照显示的只是 NSSearchField
的标准外观.也就是说,当它是 NSVisualEffectView
(带有 NSVisualEffectMaterialLight
的 material
)的子视图时,搜索字段将自动获得上方的外观.
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
).
但是,如果您希望这种外观没有 NSVisualEffectView
,则可以手动设置其外观:
However, if you want this appearance without NSVisualEffectView
, you can manually set its appearance:
searchField.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantLight];
这篇关于如何更改NSSearchField的背景颜色(例如在OS X的Messages应用程序中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!