我一直在尝试使用外观代理API将一些默认颜色应用于一些控件,但我遇到了一个问题。
当我将色调颜色应用于UISegmentedControl时,使用类似...
UISegmentedControl.appearance().tintColor = UIColor.red它会产生这样的。

一切都很好,但当我加上...
UIImageView.appearance().tintColor = UIColor.green 它会变成..。

为了清楚起见,我的代码中有这两行代码
UISegmentedControl.appearance().tintColor = UIColor.red
UIImageView.appearance().tintColor = UIColor.green无论我以什么顺序调用它们,结果都是一样的,UIImageView属性将覆盖UISegmentedControl的
我花了大半天的时间试图找到这个问题的解决方案,但似乎找不到任何有效的方法。
运行Xcode8.2、iOS 10、Swift 3
我做错了什么?我如何才能改正?
发布于 2017-02-06 16:08:20
我不确定这一点,但我猜,UISegmentedControl使用UIImageView来创建分段,即我们在分段控制中看到的分段是UIImageViews而不是UIViews。UISegmentedControl甚至有针对特定细分市场的setImage方法。
如果上述情况属实,我们可以使用UIAppearance的appearanceWhenContainedIn接口来设置画面的色调颜色,如下所示:
UIImageView.appearance(whenContainedInInstancesOf: [UISegmentedControl.self]).tintColor = UIColor.red
UIImageView.appearance().tintColor = UIColor.greenhttps://stackoverflow.com/questions/42062659
复制相似问题