如何更改UITable视图索引栏所选索引的颜色

Arv*_*ind 5 objective-c uitableview ios

UITableView索引栏中如何更改索引栏上所选索引的颜色

我使用这样的代码

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:   (NSInteger)index
{
    int i = 0;
    for (i = 0; i< [dataArray count]; i++)
    {
        NSString *letterString = [alphabetsArray objectAtIndex:i];
        if ([letterString isEqualToString:title])
        {
            [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:i] atScrollPosition:UITableViewScrollPositionTop animated:YES];
            lblSelectedIndex.text = [alphabetsArray objectAtIndex:index];

           break;
        }
    }
    return i;
}
Run Code Online (Sandbox Code Playgroud)

它滚动表上选定的索引charecter但我需要更改所选charecter的颜色.请帮助.

Aks*_*eri 2

事实上,苹果官方并没有可以做到这一点。如果你这样做,苹果可能会拒绝你的应用程序。如果您只想自定义,indexBar那么下面的库可能会帮助您(它不能自定义您当前想要的内容)。

\n\n

您可以使用自定义库GDIIndexBar(iOS 6+),您可以对其进行自定义。

\n\n

https://github.com/gdavis/GDIIndexBar

\n\n

这是示例片段GDIIndexBar

\n\n
GDIIndexBar *indexBar = [[GDIIndexBar alloc] initWithTableView:tableView];\nindexBar.delegate = self;\n[self.view addSubview:indexBar];\n
Run Code Online (Sandbox Code Playgroud)\n\n

您可以按照以下方式进行定制:

\n\n
[[GDIIndexBar appearance] setTextColor:[UIColor redColor]];\n[[GDIIndexBar appearance] setTextShadowColor:[UIColor purpleColor]];\n[[GDIIndexBar appearance] setTextFont:[UIFont italicSystemFontOfSize:11.5];\n
Run Code Online (Sandbox Code Playgroud)\n