明智地更改UISwitch的颜色 [英] Change color of UISwitch appwise

查看:87
本文介绍了明智地更改UISwitch的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iOS 3中使用UISwitch在我的应用中创建一个switch元素.它的默认颜色设置为蓝色,但我想将其颜色更改为棕色.

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.

如何在iOS 3中为UISwitch元素选择其他颜色?

How can I choose a different color for the UISwitch element in iOS 3?

如何在现代iOS应用(iOS 5+)中为UISwitch元素选择其他颜色?

How can I choose a different color for the UISwitch element in a modern iOS app (iOS 5+)?

推荐答案

对于现代iOS XX版本,请跳过答案,因为最近它的相关性为零. 还在? 在iOS 3中.您不能.但是您知道……人们因排名而降落在这里,而评论中包含其他版本和内容……

For a modern iOS XX version skip the answer as it has zero relevance lately. Still here? In iOS 3. You can't. But you know… people are landing here because of rank, and comments containing other versions and stuff so…

第五个iOS版本现在允许使用记录的方式执行此操作:使用属性onTintColor.

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.

编辑更多: 在iOS 3中,您必须使用一些未记录的功能. 此处但它坏了.而且,如果这样做,您的应用可能会因为更改颜色而被拒绝.

Edit more: In iOS 3 you had to use some undocumented feature. There used to be a link about that here but it broke. And if you did that your app might get rejected because of changing the color.

从此开始,应该足以让您在其他地方找到它:

It kind of starts with this, which should be enough for you to find it somewhere else:

UISwitch *aSwitch = [[UISwitch alloc] initWithFrame:someRectangle];
[aSwitch setAlternateColors:YES];
//Do something with aSwitch
[aSwitch release];

我不推荐它.事实证明这并不受欢迎.

I can't recommend it. And that turns out unpopular.

这篇关于明智地更改UISwitch的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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