【问题标题】:UITableView - change section header colorUITableView - 更改部分标题颜色
【发布时间】:2010-10-23 05:17:35
【问题描述】:

如何在 UITableView 中更改节标题的颜色?

编辑answer provided by DJ-S 应考虑用于 iOS 6 及更高版本。接受的答案已过期。

【问题讨论】:

  • 我非常感谢编辑 RE 较新的 iOS 版本。

标签: ios uitableview cocoa-touch


【解决方案1】:

使用 RubyMotion / RedPotion,将其粘贴到您的 TableScreen 中:

  def tableView(_, willDisplayHeaderView: view, forSection: section)
    view.textLabel.textColor = rmq.color.your_text_color
    view.contentView.backgroundColor = rmq.color.your_background_color
  end

像魅力一样工作!

【讨论】:

    【解决方案2】:

    虽然func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) 也可以工作,但您可以在不实现其他委托方法的情况下实现这一目标。 在你的 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 方法中,你可以使用 view.contentView.backgroundColor = UIColor.white 而不是 view.backgroundView?.backgroundColor = UIColor.white 这不起作用。 (我知道backgroundView 是可选的,但即使它在那里,如果不实现willDisplayHeaderView 也不会工作

    【讨论】:

      【解决方案3】:

      使用 UIAppearance,您可以为应用程序中的所有标题更改它,如下所示:

      UITableViewHeaderFooterView.appearance().backgroundColor = theme.subViewBackgroundColor

      【讨论】:

        【解决方案4】:

        iOS 13> 斯威夫特 5

        func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {view.tintColor = UIColor.red }

        【讨论】:

          猜你喜欢
          • 2011-03-18
          • 2013-01-03
          • 1970-01-01
          • 2013-02-18
          • 2023-03-04
          • 2011-04-12
          • 2015-07-26
          • 2022-08-17
          • 2011-01-24
          相关资源
          最近更新 更多