像 iOS 一样的 NSImage Overlay/Mask Gradient
我希望使用 Cocoa/Core Graphics 来复制为 UITabBarItem
设置图像时在 iOS 上发生的过程。当选择标签栏项目时,图像会覆盖渐变。
例如,
变为...
我不确定我应该做什么才能达到这种效果。看起来图像掩盖了渐变。任何正确方向的指针(或代码!)将不胜感激。
I'm looking to replicate with Cocoa/Core Graphics the process which seems to occur on iOS when setting an image for a UITabBarItem
. When the tab bar item is selected, the image is overlayed with a gradient.
For example,
becomes...
I'm unsure exactly what I should be doing to achieve this effect. It seems like the image is masking the gradient. Any pointers in the right direction (or code!) would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用带有 Alpha 通道的单色
CGImage
(如大多数 iPhone 工具/标签栏图标)作为遮罩。基本上,您可以将 CGContextClipToMask 与单色图像一起使用。然后,您将绘制渐变,然后将其剪裁到蒙版图像上。你可能还想看看 UMEKit 的代码,它在 Mac OS X 上实现了这种效果(避风港)没有看他们到底是如何做到的,可能有几种方法)。You can use a monochrome
CGImage
with alpha channel (like most iPhone tool-/tabbar icons) as a mask. Basically, you'd useCGContextClipToMask
with your monochrome image. Then you'd draw the gradient which is then clipped to the mask image. You might also want to have a look at the code of UMEKit, which implements this effect on Mac OS X (haven't looked at how exactly they do it, there are probably several ways).