gpt4 book ai didi

objective-c - tvOS : focused state interferes with text 中的 UIButton

转载 作者:搜寻专家 更新时间:2023-10-30 20:27:52 27 4
gpt4 key购买 nike

由于 tvOS 中没有 UISwitch,我使用 UIButton 来实现简单的开/关切换。我已经为 UIControlStateNormalUIControlStateSelected 设置了按钮标题文本来指示按钮的开/关状态,但是新的 UIControlStateFocused 现在会干扰这个通过将标题文本设置为与按钮处于焦点时的默认状态相同。这意味着当按钮处于“打开”状态时,只要它获得焦点,其标题就会变为“关闭”。

我发现绕过它的唯一方法是在按钮处理程序中显式设置聚焦状态的标题,如下所示。

- (void)viewDidLoad 
{
[super viewDidLoad];
// in reality these strings are setup in the storyboard
[self.enabledButton setTitle:@"Off" forState:UIControlStateNormal];
[self.enabledButton setTitle:@"On" forState:UIControlStateSelected];
// ensure the text shows up in focused state
[self.enabledButton setTitleColor:[UIColor blackColor] forState:UIControlStateFocused];
}

- (IBAction)toggleStateForEnabledButton:(id)sender
{
UIButton *button = (UIButton *)sender;
button.selected = !button.selected;
if (button.selected)
{
[button setTitle:[button titleForState:UIControlStateSelected] forState:UIControlStateFocused];
}
else
{
[button setTitle:[button titleForState:UIControlStateNormal] forState:UIControlStateFocused];
}
}

这对我来说非常骇人听闻,尤其是。因为在 UISwitch 缺席的情况下可能会发生很多事情。有没有更好的办法?

最佳答案

您是否尝试过为 UIControlStateFocused | 设置标题? UIControlStateSelected ?这是一个位字段,因此应该可以将它们组合起来。

关于objective-c - tvOS : focused state interferes with text 中的 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32974846/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com