【问题标题】:How to set a tint color for the section index of a UITableView?如何为 UITableView 的部分索引设置色调颜色?
【发布时间】:2011-02-19 03:00:59
【问题描述】:

有没有办法自定义 UITableView 的字母部分索引的灰色?

【问题讨论】:

    标签: ios iphone cocoa-touch uitableview colors


    【解决方案1】:

    从 iOS 6.0 开始,实际上可以自定义节索引的色调颜色。相关属性为:sectionIndexColorsectionIndexTrackingBackgroundColor

    iOS 7 添加了sectionIndexBackgroundColor,它指定了被触摸时节索引的背景颜色。

    【讨论】:

      【解决方案2】:

      可能有点晚了,但由于我必须使用 iOS 7 处理这个问题,所以我可能会帮助你。

      从 iOS 7 开始,有一个新方法叫做:

      @property(nonatomic, retain) UIColor *sectionIndexColor
      

      现在您可以设置在不被触摸时用于表格视图的节索引背景的颜色。

      作为适用于 iOS 6 和 7 的正确代码,您可以:

      self.friendsTableView.sectionIndexTrackingBackgroundColor = [UIColor aColor]; // background color while the index view is being touched
      if ([self.friendsTableView respondsToSelector:@selector(sectionIndexBackgroundColor)])
          self.friendsTableView.sectionIndexBackgroundColor = [UIColor aColor]; // background color while the index view is NOT touched at all
      

      【讨论】:

        【解决方案3】:

        您可能应该使用 UITableView 的 appearance proxy 来设置这些:

        [UITableView appearance].sectionIndexColor = [UIColor myTintColor];

        【讨论】:

          【解决方案4】:

          简而言之: 您可以更改字体大小和完整的背景(不是圆形的) 更多是不可能的。

          【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-11-09
          • 1970-01-01
          • 1970-01-01
          • 2023-04-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多