Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UISegmentedControl:反向着色颜色和背景颜色_Ios_Swift_Uisegmentedcontrol_Tintcolor - Fatal编程技术网

Ios UISegmentedControl:反向着色颜色和背景颜色

Ios UISegmentedControl:反向着色颜色和背景颜色,ios,swift,uisegmentedcontrol,tintcolor,Ios,Swift,Uisegmentedcontrol,Tintcolor,我有一个UISegmentedControl,我在透明背景上添加了一些白色图像 for (index,element) in ELEMENTS.enumerate() { segmentedControl.insertSegmentWithImage(element.logo, atIndex: index, animated: false) } 未选择的分段现在将背景颜色设置为segmentedControl.backgroundColor,并且图像使用segmentedContro

我有一个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
在应用程序中更改应用程序中所有视图的颜色,因此,如果这将导致在分段控件中以我希望的方式更改颜色,那就太好了


有什么想法吗?

您可以使用
UIApplication.sharedApplication().delegate?.window???.tintColor
设置应用程序所有控件使用的全局着色颜色

您可以使用
UISegmentedControl.appearance().tintColor
为应用程序中的所有分段控件设置自定义着色颜色

您可以使用
UISegmentedControl.tintColor
为特定分段控件设置自定义着色颜色

要切换应用程序中所有分段控件的背景色和色调,请执行以下操作:

UISegmentedControl.appearance().tintColor = backgroundColor
UISegmentedControl.appearance().backgroundColor = tintColor

通过设置
UISegmentedControl.tintColor
,您只能更改此控件的着色颜色。是的,但我每次都必须执行sharedApplication.delegate?.window???.tintColor=newColor和UISegmentedControl.tintColor=newColor,对吗?不。您可以使用“sharedApplication.delegate?.window???.tintColor=newColor”只设置一次全局着色颜色。每次要为此控件设置自定义着色颜色时,都要使用
UISegmentedControl.tintColor
。您还可以尝试使用
UISegmentedControl.appearance().tintColor
为应用程序中的所有分段控件设置自定义着色颜色。