我有UISegmentedControl,我在透明背景上添加了一些白色图像。未选择UISegmentedContol:reverse tintColor and backgroundColor
for (index,element) in ELEMENTS.enumerate() {
segmentedControl.insertSegmentWithImage(element.logo, atIndex: index, animated: false)
}
段现在有背景色设置为segmentedControl.backgroundColor,图像被着色segmentedControl.tintColor。所选片段反转,背景设置为.tintColor,图像用.backgroundColor着色。
这工作正常,但我希望它是另一种方式:所选段具有用.tintColor着色的图像和用背景着色的.backgroundColor。
我知道我可以通过只是切换代码的颜色做到这一点,但我使用
let sharedApplication = UIApplication.sharedApplication()
sharedApplication.delegate?.window??.tintColor = newColor
在应用更改的应用程序的所有意见的tintColor,所以这将是很好如果这会导致颜色以我想要的方式在我的分段控制中改变。
任何想法?
你可以通过设置'UISegmentedControl.tintColor'改变色调的颜色只适用于本控制。 – mixel
是的,但后来我必须每次都做sharedApplication.delegate?.window ??。tintColor = newColor和UISegmentedControl.tintColor = newColor,对吗? – Jambaman
不可以。您可以使用'sharedApplication.delegate?.window ?? tintColor = newColor'来仅设置全局色调颜色一次。每当您想为此控件设置自定义色调颜色时,都使用“UISegmentedControl.tintColor”。你也可以尝试使用'UISegmentedControl.appearance()。tintColor'为应用程序中的所有分段控件设置自定义的色调颜色。 – mixel