改变iPhone应用程序中的开关颜色 [英] change color of switch in iphone app

查看:168
本文介绍了改变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.

这篇关于改变iPhone应用程序中的开关颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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