NSPopover 颜色
有没有办法给 NSPopover 上色?我见过像 Facetab 等应用程序有很酷的颜色和可调整大小的弹出窗口,这是如何完成的?
有指导、提示吗?
谢谢。
Is there any way to color NSPopover? Ive seen apps like facetab etc that have cool colors and resizeable popovers, how is this done?
Ay guides, hints?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
将
popover.contentViewController.view
设置为具有自定义背景绘图的NSView
子类(即覆盖drawRect:
并使用自定义背景填充矩形颜色)。然后设置 popover.appearance = NSPopoverAppearanceHUD 以删除视图周围的默认边框。
请注意,视图周围仍然会有一个非常细的边框,因此如果您想完全删除它,您可能需要使用 MAAttachedWindow 或类似的解决方案。
Set
popover.contentViewController.view
as a subclass ofNSView
with a custom background drawing (i.e. overridedrawRect:
and fill a rect with your custom background color).Then set the
popover.appearance = NSPopoverAppearanceHUD
to remove the default border around the view.Note that there will still be a very thin border around the view, so if you want to remove it completely, you may want to use MAAttachedWindow or a similar solution.
在 Swift 4 中:
在故事板中,选择具有弹出窗口内容的视图,然后转到身份检查器
将类设置为 PopoverContentView
您的弹出窗口及其三角形现在将变为绿色。
In Swift 4:
In your storyboard, select the view which has your popover content and go to the Identity Inspector
Set the Class to PopoverContentView
Your popover and its triangle will now be green.
您可以使用 MAAttachedWindow 代替。
You can use MAAttachedWindow instead.
您可以继承
NSView
并将其设置为NSPopover
的视图控制器的视图。You can subclass
NSView
and set it as theNSPopover
's view controller's view.是和不是。不幸的是,
NSPopover
并不是可定制的。您可以使用一些简单的技巧在contentViewController
的view
后面添加额外的背景视图,并根据需要对其进行着色或自定义。在这种情况下,您可以获得可自定义的背景,该背景将与通用NSPopover
边框和尾部一样进行屏蔽。有关更多详细信息,您可以查看
NSPopover+MISSINGBackgroundView
类实现了这种方法或者只是使用这段代码作为 CocoaPod 库。Yes and no. Unfortunately
NSPopover
isn't designed to be customisable. You can use some simple hacks for adding additional background view behindcontentViewController
'sview
and colorise or customise it as you want. In this case, you can get the customisable background that will be masked the same as genericNSPopover
border and tail.For more details you can take a look at the code of
NSPopover+MISSINGBackgroundView
category that implements this approach or just use this piece of code as CocoaPod library.更改 NSPopover 颜色(包括三角形)的完整代码如下:
我假设人们已经挂钩了弹出窗口出口和方法
The complete code to change the color of NSPopover including the triangle is here:
I assume people have hooked the popover outlets and methods
这就是我改变弹出窗口颜色所做的。
假设您已正确定义 NSPopover:
NSPopover 类参考 - 我真的希望他们能在开发人员文档中提供使用代码。
This is what I did to change the popover color.
Assuming that you have properly defined your NSPopover:
NSPopover Class Reference - I really wish they would provide usage code in the developer docs.