我想在 tvOS 中突出显示 UISegmentedControl 时更改其背景颜色。
How to change white background when UISegmentedControl focused?
我尝试遵循一些事情,但没有成功。
1) 创建 UISegmentedControl 的自定义类并在 awakeFromNib 中执行以下代码
[self setBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self setBackgroundImage:image forState:UIControlStateFocused barMetrics:UIBarMetricsDefault];
2) 重写 UISegmentedControl 的 setHighlighted 方法
3)在didUpdateFocusInContext方法中更改背景颜色。
最佳答案
根据我对你的问题的理解,你想将背景颜色更改为与 UISegmentControl 色调颜色相同。您需要做的就是简单地使用这个:
label.backgroundColor = segmentedControl.tintColor;
如果你不尝试的话,希望这会对你有所帮助:
您只需指定其背景颜色即可从 Storyboard 中清除。发生这种情况是由于默认背景选择和默认选择是根据主题。一旦您将segmentControl背景颜色设置为清除,您将获得所需的结果。
或者你可以这样做: 尝试在 viewDidLoad 中将 UISegmentcontrol 背景颜色设置为清除,您将得到结果。我已经尝试过了,它对我有用。
segment.backgroundColor = Color.clear;
关于ios - tvos UISegmentedControl 焦点样式不改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58449340/