在iOS7上更改UI开关的颜色?

在iOS7上更改UI开关的颜色?,ios,ios7,uiswitch,Ios,Ios7,Uiswitch,我在iOS7上看到默认的onTintColor是绿色的,但我希望它是另一种颜色 [myUISwitch setOnTintColor:[UIColor customColor]]; 不起作用打开/关闭图像对iOS7没有影响,如文档所述。为什么它不能工作?如何更改其onTintColor UISwitch *switch = [UISwitch alloc] init]; [switch setOnTintColor:[UIColor customColor]]; [myView addSubv

我在iOS7上看到默认的
onTintColor
是绿色的,但我希望它是另一种颜色

[myUISwitch setOnTintColor:[UIColor customColor]];
不起作用<代码>打开/关闭图像对iOS7没有影响,如文档所述。为什么它不能工作?如何更改其
onTintColor

UISwitch *switch = [UISwitch alloc] init];
[switch setOnTintColor:[UIColor customColor]];
[myView addSubview:switch];
不起作用。但是

UISwitch *switch = [UISwitch alloc] init];
[myView addSubview:switch];
[switch setOnTintColor:[UIColor customColor]];

工作。着色颜色不会改变,除非它是可见的。有人来解释吗?

设置
onTintColor
对我很有用。您确定调用时myUISwitch不是
nil
吗?调用alloc和init后,交换机的视图层次结构在显示并调用viewDidLoad:之前不会完全初始化。啊,这太烦人了。我真的很想知道苹果有时会发生什么。如果你想改变它,还有
thumbTintColor
属性。对于斯威夫特来说,这仍然适用。将其设置为单元格的awakeFromNib没有效果;您必须在LayoutSubView或在添加开关后调用的其他地方设置它