我有一个UISegmentedControl,我在透明的背景上添加了一些白色的图像。
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,所以如果这将导致在我的分段控件中以我希望的方式改变颜色,那就太好了。
有什么想法吗?
发布于 2015-10-18 19:46:06
使用UIApplication.sharedApplication().delegate?.window??.tintColor设置应用程序的所有控件所使用的全局色调颜色。
可以使用UISegmentedControl.appearance().tintColor为应用程序中的所有分段控件设置自定义颜色。
您还可以使用UISegmentedControl.tintColor为特定分段控件设置自定义的淡色颜色。
若要为应用程序中的所有分段控件切换背景和色调颜色,请执行以下操作:
UISegmentedControl.appearance().tintColor = backgroundColor
UISegmentedControl.appearance().backgroundColor = tintColorhttps://stackoverflow.com/questions/33201494
复制相似问题