【问题标题】:UITableViewHeaderFooterView remove transparencyUITableViewHeaderFooterView 移除透明度
【发布时间】:2014-07-09 09:34:16
【问题描述】:

我做了一些搜索,很多答案都说我需要创建一个自定义UIView 并将其粘贴到UITableViewHeaderFooterView

目前,我正在像这样设置 AppDelegate 中的外观

   [[UITableViewHeaderFooterView appearance] setTintColor:[UIColor redColor]];

但我想摆脱透明度。有没有办法从 appDelegate 做到这一点,而不必通过我的整个应用程序并在使用 tableView 的地方更改UITableViewHeaderFooterView

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    不幸的是,UITableViewHeaderFooterView 将其backgroundViewbackgroundColor 设置为其tintColor 的稍微透明的版本。

    作为一种解决方法,您可以设置UITableViewHeaderFooterView 的任何子视图的backgroundColor

    [[UIView appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setBackgroundColor:[UIColor redColor]];
    

    【讨论】:

      【解决方案2】:

      您现在可以在 Swift 中通过实现 tableView( willDisplayHeaderView:forSection) 委托方法并覆盖 backgroundConfigurationbackgroundColor 来完成此操作,如下所示:

      func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
          guard let headerFooter = view as? UITableViewHeaderFooterView else {
              return
          }
              
          headerFooter.backgroundConfiguration?.backgroundColor = <color>           
      }
      

      headerFooter 的 UILabel 可以通过headerFooter.textLabel? 访问,如果您还想自定义页眉/页脚的字体、颜色等。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-14
        • 1970-01-01
        • 2014-01-05
        • 2017-01-31
        相关资源
        最近更新 更多