tvos UISegmentedControl焦点样式不变 [英] tvos UISegmentedControl focus style not change

查看:58
本文介绍了tvos UISegmentedControl焦点样式不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在tvOS中突出显示UISegmentedControl的背景颜色.

I want to change background color of UISegmentedControl when it highlighted in tvOS.

通常分段显示如下.

Normally Segment display like following.

当此时改变所选片段的焦点时,显示如下.

When change focus for change selected segment at that time display like following.

如何在UISegmentedControl聚焦时更改白色背景?

How to change white background when UISegmentedControl focused?

我正在尝试跟踪事情,但是没有用.

I was try following things but not working.

1)创建UISegmentedControl的自定义类,并在 awakeFromNib

1) create custom class of UISegmentedControl and do following code in awakeFromNib

[self setBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self setBackgroundImage:image forState:UIControlStateFocused barMetrics:UIBarMetricsDefault];

2)覆盖UISegmentedControl的 setHighlighted 方法

2) override setHighlighted method of UISegmentedControl

3)使用 didUpdateFocusInContext 方法更改背景颜色.

3) change background color in didUpdateFocusInContext method.

推荐答案

根据我对您问题的理解,您希望更改与UISegmentControl着色颜色相同的背景颜色.您只需要使用以下内容即可:

From my understanding of your question, you want to change the background color same as UISegmentControl tint color. What you need to do is simply use this:

label.backgroundColor = segmentedControl.tintColor;

希望这可以帮助您,如果不尝试的话:

Hope this will help you if not try this:

您只需要提供其背景颜色即可从情节提要中清除.这是由于默认的背景选择和默认选择是根据主题而发生的.将segmentControl的背景色设置为清除后,您将获得所需的结果.

You just need to give its background color to clear from storyboard. This is happening due to default background selection and default selection is as per theme. Once you set the segmentControl background color to clear you will get the required result.

或者您可以执行以下操作:尝试将您的UISegmentcontrol背景颜色设置为在viewDidLoad中清除,您将获得结果.我已经尝试过了,并且对我有用.

Or you can do: Try to set your UISegmentcontrol background color to clear in viewDidLoad, you will get your result. I have tried this and it worked for me.

segment.backgroundColor = Color.clear;

这篇关于tvos UISegmentedControl焦点样式不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆