1

我想为项目制作自定义 UISwitch。我想更改文本和背景。

为此,我浏览了有关堆栈溢出的多个帖子。有些只是图像绘制或核心图形绘制。我不想要它们,因为它们还不够。

  1. 自定义 UISwitch 和 App Store 批准
  2. UISwitch - 从开/关更改为是/否
  3. http://www.catamount.com/blog/uicustomswitch-customizing-uiswitch-color-it-change-labels/

但我需要一个对于iOS 4.2 和 iOS 6.0 都足够的代码。

4

2 回答 2

2

使用它来改变背景颜色。这会更改 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 希望它对你有所帮助。

于 2013-05-27T13:02:34.210 回答
1

每当我需要一些开源组件时,我都会去cocoacontrols:也许这个https://www.cocoacontrols.com/controls/ssswitch(我还没试过......)

于 2013-05-27T13:00:37.560 回答