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 sectionIndexTitlesForTableView means the vertical bar in right hand side to show the the titles for the sections.
Thanks.
Swift 3
you can just set the:
tableView.sectionIndexColor
to whatever color your want like:
tableView.sectionIndexColor = .red
Go to the IB and change the text COLOR to white, Works for me
//=========================================
And in Swift, you can also change Programatically by:
self.my_tableView.sectionIndexColor = UIColor.greenColor()
Following code is a straight solution. api is available from iOS 6
[tableView setSectionIndexColor:[UIColor greenColor]];
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
}
Write Bellow code in your viewDidLoad (for swift)
tableName.sectionIndexColor = UIColor.lightGrayColor()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With