xcode UISwitch 的颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3900737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:49:37  来源:igfitidea点击:

UISwitch's color

iphonexcodeios4

提问by Fry

I can change UISwitch's color with below code but always color is yellow how to change color to another color?

我可以使用以下代码更改 UISwitch 的颜色,但颜色始终为黄色 如何将颜色更改为另一种颜色?

UISwitch *switch1=[[UISwitch alloc]initWithFrame:CGRectMake(70, 121, 94, 27)];
[switch1 setAlternateColors:YES];

回答by Fry

Finally, with iOS5 you can change the color of the switch with the property onTintColor.

最后,在 iOS5 中,您可以使用属性更改开关的颜色onTintColor

UISwitch *s = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
s.on = YES;
s.onTintColor = [UIColor redColor];
[self.view addSubview:s];
[s release];

produce this

生产这个

enter image description here

在此处输入图片说明

I hope this help !

我希望这有帮助!

回答by I?igo Beitia

Check this pagefor a project with a custom switch.

检查此页面以获取带有自定义开关的项目。

回答by taskinoor

From the UISwitch reference, "The UISwitch class is not customizable." So you can't change the appearance of UISwitch.

来自UISwitch 参考,“UISwitch 类不可自定义”。所以你不能改变 UISwitch 的外观。