I need to change the color of sectionIndexTitlesForTableView in iOS 5. I could not find any method in the APIs to do the task. Can anyone offer me some help?
The se
Unfortunately I think there is no documented way to customize your index.
Try to take a look to these Q&A:
sectioned tableview index selection highlighting
How do I change the color of the side Alphabet in an indexed UITableView?
Swift 2.0
The code line below will change the font color of the section index on table view. I have attached the resulting screenshot of the implementation.
self.tblYourTableView.sectionIndexColor = UIColor.redColor()
- (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
}
You can also change the section index colors by changing the tintColor of the tableView.
tableView.tintColor = .red
Write Bellow code in your viewDidLoad (for swift)
tableName.sectionIndexColor = UIColor.lightGrayColor()
Swift 3
you can just set the:
tableView.sectionIndexColor
to whatever color your want like:
tableView.sectionIndexColor = .red