Changing the color of NSProgressIndicator?

一曲冷凌霜 提交于 2019-11-30 05:12:37

问题


What is the best way to change the color of NSProgressIndicator, is there an easier way than just to subclass it and then draw the whole component by myself?

Basically what I want to do is to have a similar component but with the ability to change the color of the bar.

I tried to google this but all the questions were quite outdated and didn't really concern the 10.10 OS X version that I am working on. Also checked cocoa controls and did only find 1 component that was for outdated OS X version.


回答1:


You can use Quartz filters (e.g. hue adjust) for this directly in Interface Builder. This works better than expected.

It's in the Effects Inspector. Under "Content Filters" you can add "Hue Adjust"




回答2:


To change color of NSProgressIndicator use setControlTint: method. If you want to set custom color you have to draw such control manually. However, you should use the system color to keep this kind of control consistent across the system.




回答3:


For Swift the method name is controlTint.

progressIndicator = NSProgressIndicator(frame: .......
progressIndicator.controlTint = .blueControlTint



回答4:


Use "CIFalseColor" filter to get white color and more.

let colorFilter = CIFilter(name: "CIFalseColor")!
colorFilter.setDefaults()
colorFilter.setValue(color1, forKey: "inputColor0")
colorFilter.setValue(color2, forKey: "inputColor1")
proggressBar?.contentFilters = [colorFilter]


来源:https://stackoverflow.com/questions/31506002/changing-the-color-of-nsprogressindicator

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