【问题标题】:How to set UISwitch border color?如何设置 UISwitch 边框颜色?
【发布时间】:2014-03-24 10:36:03
【问题描述】:

我的应用有:

[[UIView appearance] setTintColor:[UIColor whiteColor]];

这是我在on时所拥有的:

off:

我需要像在 Settings.app 中一样使UISwitch 边框可见:

【问题讨论】:

  • 对于任何想要获得这种外观的人,我将在接受的答案下重复我评论的本质:将色调颜色设置为浅灰色或“灰白色”(a约 80% 白色的自定义颜色)。然后该边框将显示为白色。

标签: ios uiswitch tintcolor


【解决方案1】:

除了使用外观代理,您还可以使用:

[self.mySwitch setThumbTintColor:[UIColor blueColor]];
[self.mySwitch setOnTintColor:[UIColor redColor]];

即。使用setOnTintColor 作为背景/边框颜色。

【讨论】:

    【解决方案2】:

    请您尝试将此行添加到您的 AppDelegate 的didFinishLaunchingWithOptions

    [[UISwitch appearance] setTintColor:[UIColor grayColor]];
    

    这应该在所有 UISwitch 控件上应用所选的 Tint 颜色。

    【讨论】:

      【解决方案3】:

      您的[[UIView appearance] setTintColor:[UIColor whiteColor]]; 干扰了开关的色调。设置着色颜色的命令是self.mySwitch.tintColor = [UIColor grayColor];,它设置关闭时用于着色开关轮廓的颜色。

      【讨论】:

      • 如果去掉[[UIView外观] setTintColor:[UIColor whiteColor]];那么它将起作用。我跑了一个测试,没有设置 UIView tintColor 你会得到你需要的任何颜色的 UISwitch 边框。
      • 是的,它有效,但我需要将色调设置为白色。我想要这一步self.mySwitch.tintColor = [UIColor grayColor]; 来解决我的问题,但不是……
      • 你用 self.view.backgroundColor = [UIColor whiteColor]; 是否可行而不是 [[UIView 外观] setTintColor:[UIColor whiteColor]]; ?
      • 正如我所说,我测试了它,您无法使用 setTintColor 获得您想要的结果。如果使用设置背景颜色确实不能满足您的目标,我建议发布一个新问题,专门询问如何在 setTintColor 设置为白色时显示 UISwitch 边框。对不起,我帮不了你。
      • 为了澄清其他阅读此答案的人: tint color (currently) only 控制 当开关关闭时显示的边框颜色 - 这就是在这里通缉。要使其对白色可见,请将其设置为白色以外的任何颜色。要匹配问题中显示的外观,请将其设置为浅灰色或“灰白色”(不是 100% 白色的自定义值,可能是 80%)。
      猜你喜欢
      • 1970-01-01
      • 2014-12-14
      • 2013-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多