0

我正在使用此代码更改切换开关的颜色,当它处于“ON”模式时,

toggleSwitch.onTintColor=[UIColor orangeColor];

当开关处于“关闭”模式时,有什么方法可以改变颜色吗?因为当它处于“关闭”模式时,它变得透明。

编辑:

toggleSwitch.onTintColor=[UIColor orangeColor];
            toggleSwitch.tintColor=[UIColor redColor];
            toggleSwitch.thumbTintColor=[UIColor redColor];

也,没用。当开关“关闭”时,它的内部总是透明的。

4

4 回答 4

1

当您使用以下代码打开和关闭它时,您可以更改 toggleSwitch 的颜色。

- (IBAction)switchAction:(UISwitch *)sender
{
    if(sender.isOn) {
        sender.onTintColor = [UIColor redColor];
        sender.thumbTintColor = [UIColor blackColor];

    } else {
        sender.tintColor = [UIColor greenColor];
    }
}
于 2013-09-09T08:17:29.053 回答
0
tintColor

禁用开关时用于着色外观的颜色。

@property(nonatomic, retain) UIColor *tintColor

查看文档

于 2013-09-09T06:49:27.613 回答
0

设置开关关闭时切换开关的 tintColor。

你可以检测开关状态

if(toggleSwitch.isOn]))
于 2013-09-09T06:50:00.853 回答
0

虽然派对迟到了,但对于未来的用户......

XCode 的方法是 Seton tinttint.

参考图片:

上色

于 2018-05-23T14:23:32.713 回答