【问题标题】:Changing onTintColor of UISwitch on iOS7?在 iOS7 上更改 UISwitch 的 onTintColor?
【发布时间】:2013-11-25 15:09:07
【问题描述】:

默认 onTintColor 在 iOS7 上是绿色的,但我希望它是另一种颜色。

[myUISwitch setOnTintColor:[UIColor customColor]];

不起作用。如文档所述,on/offImages 对 iOS7 没有影响。为什么它不能工作?如何更改其onTintColor

【问题讨论】:

  • 设置onTintColor 对我有用。您确定拨打电话时myUISwitch 不是nil

标签: ios ios7 uiswitch


【解决方案1】:
UISwitch *switch = [UISwitch alloc] init];
[switch setOnTintColor:[UIColor customColor]];
[myView addSubview:switch];

不起作用。但是

UISwitch *switch = [UISwitch alloc] init];
[myView addSubview:switch];
[switch setOnTintColor:[UIColor customColor]];

有效。除非可见,否则色调颜色不会改变。有人解释一下吗?

【讨论】:

  • 在你调用 alloc 和 init 之后,switch 的视图层次结构在你显示它并调用 viewDidLoad: 之前并没有完全初始化。
  • 呃,太烦人了。我真的很想知道 Apple 有时会发生什么。
  • 如果你想改变它,还有 thumbTintColor 属性。
  • 对于 Swift 这仍然适用。在 awakeFromNib 中为单元格设置它没有效果;你必须在 layoutSubviews 或其他地方设置它添加开关之后
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-02-09
  • 2011-02-12
  • 2013-10-08
  • 2011-11-16
  • 1970-01-01
  • 2023-03-18
  • 1970-01-01
相关资源
最近更新 更多