我一直在尝试使用外观代理 API 将一些默认颜色应用于某些控件,但遇到了问题。
当我应用色调颜色时UISegmentedControl
使用类似...
UISegmentedControl.appearance().tintColor = UIColor.red
它生成这个...
一切都很好,但是当我添加...
UIImageView.appearance().tintColor = UIColor.green
它变成...
需要明确的是,我的代码中有这两行
UISegmentedControl.appearance().tintColor = UIColor.red
UIImageView.appearance().tintColor = UIColor.green
无论我以什么顺序调用它们,结果都是一样的,UIImageView
属性覆盖UISegmentedControl
s
我花了半天多的时间试图找到解决这个问题的方法,但似乎找不到任何有效的方法。
运行 Xcode 8.2、iOS 10、Swift 3
我做错了什么以及如何解决?
我对此不太确定,但我猜,UISegmentedControl
uses UIImageView
创建段,即我们在分段控件内看到的段是UIImageViews
并不是UIViews
. UISegmentedControl
甚至有为特定片段设置图像的方法。
如果上述为真,我们可以使用appearanceWhenContainedIn APIUIAppearance
像这样设置图像视图色调颜色:
UIImageView.appearance(whenContainedInInstancesOf: [UISegmentedControl.self]).tintColor = UIColor.red
UIImageView.appearance().tintColor = UIColor.green
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)