【问题标题】:UItableViewCell setTextColor deprecatedUItableViewCell setTextColor 已弃用
【发布时间】:2015-12-24 19:37:02
【问题描述】:

我正在尝试使用 appearanceWhenContainedInInstancesOfClasses 作为我应用程序中的主题来更改 UITableViewCell 中的文本颜色。

这是代码行:

[[UITableViewCell appearanceWhenContainedInInstancesOfClasses:@[[SearchTableView class]]] setTextColor:snackOrangeColor];

这行得通。但是 setTextColor 在 iOS 3.0 中已被弃用。因此,我不能使用它。我还没有找到合适的解决方案。

我的问题是我应该用什么来改变 UITableViewCell 中的文本颜色来代替 setTextColor?

感谢大家的帮助。

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    尝试更改单元格的 textLabel 的 textColor。

     cell.textLabel.textColor = [UIColor someColor];
    

    创建自定义 UITableViewCell

    [[UILabel appearanceWhenContainedIn:[CustomUITableViewCell class], nil] 
     setTextColor:[UIColor someColor]];
    

    我认为不会有替代方案。我建议在常量中创建颜色并在代码中调用常量。

    【讨论】:

    • 我知道这种方法。但我需要使用 UIAppearance,因为我正在为应用程序制作主题。
    • 我想这是唯一的方法。谢谢。
    【解决方案2】:

    为cell创建自定义类,然后拖拽UILabel的OUTlet。然后使用该自定义单元格。

    【讨论】:

    【解决方案3】:

    添加“textLabel”是正确的

    [[UITableViewCell appearanceWhenContainedInInstancesOfClasses:@[[SearchTableView class]]].textLabel setTextColor:snackOrangeColor];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-12
      • 1970-01-01
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      相关资源
      最近更新 更多