在Swift 3中以编程方式设置内容过滤器 [英] Programmatically set Content Filters in Swift 3
问题描述
如此答案中所述,可以使用内容过滤器更改进度条的颜色,例如(在这种情况下,是色相调整"内容过滤器).
As described in this answer, it is possible to change, for example, the color of a progress bar using a Content Filter (in this specific case, the "Hue Adjust" Content Filter).
似乎您只能在Xcode的Interface Builder中实现此目标;但是,我想以编程方式启用/禁用内容过滤器.因此,例如,我想启用色相调整内容过滤器",以便进度条变为绿色,并稍后在某个功能中将其禁用,从而恢复为蓝色.这可能吗?
It seems like you can only achieve this from within Xcode's Interface Builder; however, I'd like to programmatically enable/disable Content Filters. So, for example, I'd like to enable the Hue Adjust Content Filter so that the progress bar turns is green, and disable it sometime later from within a function, so that goes back to blue. Is this possible?
推荐答案
错误的开始之后,答案似乎很简单:
After a false start, it seems like the answer is real simple:
// Need to set this in code. The settings in IB don't carry over when
// I change the contentFilters
progressIndicator.minValue = 0
progressIndicator.maxValue = 100
progressIndicator.doubleValue = 50
let hueAdjust = CIFilter(name: "CIHueAdjust", withInputParameters: ["inputAngle": NSNumber(value: 1.7)])!
progressIndicator.contentFilters = [hueAdjust]
这篇关于在Swift 3中以编程方式设置内容过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!