【问题标题】:How to change color of letters of sectionIndexTitlesForTableView?如何更改 sectionIndexTitlesForTableView 的字母颜色?
【发布时间】:2012-01-23 11:54:34
【问题描述】:

我需要在 iOS 5 中更改 sectionIndexTitlesForTableView 的颜色。我在 API 中找不到任何方法来执行该任务。谁能帮帮我?

sectionIndexTitlesForTableView 表示右侧的竖条,用于显示部分的标题。

谢谢。

【问题讨论】:

    标签: iphone ios ipad


    【解决方案1】:

    转到 IB 并将文本颜色更改为白色,为我工作

    //==========================================

    在 Swift 中,您还可以通过以下方式以编程方式更改:

    self.my_tableView.sectionIndexColor = UIColor.greenColor()
    

    【讨论】:

    • 这也适用于我 - 这应该是正确的答案。
    • 这个问题是2012年问的,和iOS 5有关!!现在工具发生了变化,这是正确的答案。
    • @Beppe 我明白了。即使有些人没有。我在 2013 年遇到过这件事。所以我相应地发布了。
    【解决方案2】:

    以下代码是直接的解决方案。 api 可从 iOS 6 获得

     [tableView setSectionIndexColor:[UIColor greenColor]];
    

    【讨论】:

      【解决方案3】:

      斯威夫特 3

      你可以设置:

      tableView.sectionIndexColor 
      

      你想要的任何颜色:

      tableView.sectionIndexColor = .red
      

      【讨论】:

        【解决方案4】:

        Swift 2.0

        下面的代码行将改变表格视图中部分索引的字体颜色。我附上了执行结果的屏幕截图。

        self.tblYourTableView.sectionIndexColor = UIColor.redColor()
        

        【讨论】:

          【解决方案5】:
          - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
          {
          
          
              for(UIView *view in [tableView subviews])
              {
                  if([[[view class] description] isEqualToString:@"UITableViewIndex"])
                  {
                  [view performSelector:@selector(setIndexColor:) withObject:[UIColor redColor]];
                  }
              }
          
          
          
              static NSString *MyIdentifier = @"MyIdentifier";
          
          //***Table cell create
          
          }
          

          【讨论】:

            【解决方案6】:

            在您的 viewDidLoad 中编写 Bellow 代码(用于 swift)

            tableName.sectionIndexColor = UIColor.lightGrayColor()

            【讨论】:

              【解决方案7】:

              你也可以通过改变tableView的tintColor来改变section索引颜色。

              tableView.tintColor = .red
              

              【讨论】:

              • 有效! @ricks 的这个或答案应该被标记为正确的:tableView.sectionIndexColor = .red
              【解决方案8】:

              很遗憾,我认为没有记录在案的方法来自定义您的索引。

              试着看看这些问答:

              sectioned tableview index selection highlighting

              How do I change the color of the side Alphabet in an indexed UITableView?

              【讨论】:

              • 致 Downvoter -> 你知道这是在 2012 年提出的吗?那现在我们有不同的工具吗?好...
              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2014-11-26
              • 2010-10-19
              • 2013-03-04
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多