Mad*_*mer 2 uisegmentedcontrol uiimageview ios swift
我一直在尝试使用外观代理API将一些默认颜色应用到某些控件,但我遇到了一个问题.
当我使用淡色调来UISegmentedControl使用类似......
UISegmentedControl.appearance().tintColor = UIColor.red
Run Code Online (Sandbox Code Playgroud)
它产生了这个......
一切都很好,但是当我添加...
UIImageView.appearance().tintColor = UIColor.green
Run Code Online (Sandbox Code Playgroud)
它改为......
为了清楚起见,我的代码中有这两行
UISegmentedControl.appearance().tintColor = UIColor.red
UIImageView.appearance().tintColor = UIColor.green
Run Code Online (Sandbox Code Playgroud)
按我调用它们的顺序无关紧要,结果是相同的,UIImageView属性覆盖UISegmentedControls
我花了半天时间试图找到解决这个问题的方法,但似乎找不到任何有效的方法.
运行Xcode 8.2,iOS 10,Swift 3
我做错了什么,我该怎么办?
我不知道这一点,但我想,UISegmentedControl用UIImageView创建段,即段,我们看到里面分段控制的UIImageViews,而不是UIViews.UISegmentedControl甚至有特定段的setImage方法.
如果以上是真的,我们可以使用appearanceWhenContainedIn API UIAppearance来设置图像视图色调颜色如下:
UIImageView.appearance(whenContainedInInstancesOf: [UISegmentedControl.self]).tintColor = UIColor.red
UIImageView.appearance().tintColor = UIColor.green
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
375 次 |
| 最近记录: |