使用它来改变背景颜色。这会更改 UISwitch 控件的关闭颜色
// Set the tint color for the On state. Here we set green colour tint for On state
[customizedSwitch setOnTintColor:[UIColor colorWithRed:64.0/255 green:128.0/255.0 blue:64.0/255.0 alpha:1.0]];
// Set the tint color for the Off state. Here we set green red tint for Off state
[customizedSwitch setTintColor:[UIColor colorWithRed:255.0/255 green:128.0/255.0 blue:128.0/255.0 alpha:1.0]];
// Set the tint color for the round shaped Thumb. Here we set blue tint for the Thumb
[customizedSwitch setThumbTintColor:[UIColor colorWithRed:64.0/255 green:64.0/255.0 blue:255.0/255.0 alpha:1.0]];
注意:绝对不支持修改框架控件的私有视图层次结构,如果您尝试使用 uiswitch 的子视图更改文本,可能会导致与操作系统更新不兼容。
使用这个很好的教程来完成这两个任务:customizing-user-interface-uiswitch
希望它对你有所帮助。