改变iPhone应用程序中的开关颜色
我在iOS 3中使用 UISwitch
在我的应用中制作一个开关元素。它的默认颜色设置为蓝色,但我想将其颜色更改为棕色(除了一些令人讨厌的谣言之外,没有通过谷歌获得线索)。
I am using UISwitch
in iOS 3 to make a switch element in my app. It has default color set to blue, but I want to change its color to brown (didn't get a clue via Google except some nasty rumors).
我怎么能为iOS 3中的 UISwitch
元素选择不同的颜色?
How can I choose a different color for the UISwitch
element in iOS 3?
在iOS 3中,您可以使用未记录的功能找到答案这里。如上所述,您的应用可能会因为更改颜色而被拒绝。
In iOS 3 you will find an answer by using an undocumented feature here. As noted your app might get rejected because of changing the color.
它的开头是这样的:
UISwitch *aSwitch = [[UISwitch alloc] initWithFrame:someRectangle];
[aSwitch setAlternateColors:YES];
//Do something with aSwitch
[aSwitch release];
第五个iOS版本现在允许以书面形式执行此操作:使用属性 onTintColor
。
And the fifth iOS release now allows a documented way of doing this: with the property onTintColor
.
UISwitch *s = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
s.on = YES;
s.onTintColor = [UIColor redColor];
[self.view addSubview:s];
[s release];
产生此
编辑我不知道为什么有人会通过并回滚答案,只有在对所有答案做同样的事情时才将其限制在问题中。
I have no idea why someone would come through and roll back the answer to limit it to the question only while not doing the same to all the answers.