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

I have a table view with an alphabetical index and am using the side alphabet to get through the list quickly. For those not familiar, that uses this:

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {

My problem is that my application has just been skinned black. And so now it's hard to see the alphabet letters on the side.

I can't figure out how to change the color of the alphabet. I'd like it to be 'white' if at all possible.

From what I can tell unfortunately it is not possible to customize the color of the text displayed in the index, the closest I've been able to come is being able to modify the background color and the font of the index.

There is some code in the iPhone Developers cookbook by Erica Sadun which shows how to access the UITableViewIndex view (an undocumented class). You can find the reference to it on page 175 of the book if you have it. Which gives access to the background color and the font. You can see an unofficial document related to this class here.

WARNING This is undocumented use of an undocumented class so you need to be cautious about using it.

Here is a code snippet from the cookbook with minor modifications:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {    

  for(UIView *view in [tv subviews])
  {
    if([[[view class] description] isEqualToString:@"UITableViewIndex"])
    {

      [view setBackgroundColor:[UIColor whiteColor]];
      [view setFont:[UIFont systemFontOfSize:14]];
    }
  }

  //rest of cellForRow handling...

} 

This illustrates how you can access and the UITableViewIndex view and modify it in some aspects. It looks like the view doesn't have any subviews so it is likely doing some custom drawing with the array of index titles.

It's not perfect but hopefully it helps a little.

Paul

How to change color of letters of , 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  How to change the color of the alphabet from the side in an indexed UITableView? I have a table view with an alphabetical index and am using the side alphabet to get through the list quickly. For those not familiar, that uses this: - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atInd

if your minimum iOS version is newer than 6.0, you can use sectionIndexColor property of UITableView.

The color to use for the table view’s index text.

@property(nonatomic, retain) UIColor *sectionIndexColor

Discussion:

Table views can display an index along the side of the view, making it easier for users to navigate the contents of the table quickly. This property specifies the color to use for text displayed in this region.


Update date 2014.1.13

I find an open source third party library:GDIIndexBar to help custom the index appearance.

Font color of UITableView indexing[A-Z] o…, There's no way to change the font color of the UITableView index. I think the discussion at this link is accurate:  iphone - How do I change the color of the side Alphabet in an indexed UITableView? I have a table view with an alphabetical index and am using the side alphabet to get through the list quickly. For those not familiar, that uses this:-(NSInteger)tableView:(UITableView*)tableView…

This can be easily changed in the interface builder for the UITableView - No need to use undocumented classes?

See screenshot below, as you can see the font colour and the background colour can be changed too. Job's a good'n!

How to change color of letters of , 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? cellForRowAtIndexPath: method – this method shouldn’t be new to you if you know how to display data in UITableView. It returns the table data for a particular section. sectionIndexTitlesForTableView: method – returns the indexed titles that appear in the index list on the right side of the table view. For example, you can return an array of strings containing “A” to “Z”.

For iOS7 or Higher:

self.tableView.sectionIndexColor = [UIColor whiteColor];
self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];

Is there any way to style a tableview index? » Community Questions , It is possible to change the text colour of the tableview index bar. It's using /​750119/how-do-i-change-the-color-of-the-side-alphabet-in-an-indexed-​uitableview. How to change the iOS UITableView Color Index? This question already has an answer here: Customising the font/background colour of index/section bar in UITableView 3 answers How do I customise the Color and Font of the right side list.Use UITableView methods sectionIndexColor and sectionIndexBack

I was having the same problem and just found out a way of doing this, though this is using undocumented classes and methods so think one extra time before trying to upload it to the App Store. I should say that i've only tried this with iOS5 so I don't know if it will work for previous versions.

I borrowed and modified the Erica Saunders cookbook example so that it now changes the text color to red:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {    

  for(UIView *view in [tv subviews])
  {
    if([[[view class] description] isEqualToString:@"UITableViewIndex"])
    {
      [view performSelector:@selector(setIndexColor:) withObject:[UIColor redColor]];
    }
  }

  //rest of cellForRow handling...

}

change color of selected index in uitablleview, How do I change the color of the side Alphabet in a selected index UITableView? - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { mon problème est que mon application vient d'être écorchée en noir. Et donc maintenant c'est dur de voir les lettres de l'alphabet sur le côté. Je ne sais pas comment changer la couleur de l'alphabet.

iphone - Cómo cambiar el color de las letras de , How do I change the color of the side Alphabet in an indexed UITableView? Ir al IB y cambiar el color del texto a blanco, Funciona para mí enter image  21 How do I change the color of the side Alphabet in an indexed UITableView? 19 How to Restrict the iOS app only for iPhone excluding iPad? 17 Change the height of UISegmentedControl in iOS

Adding Section and Index List in UITableView, An indexed table view is more or less as the plain-styled table view titles that appear in the index list on the right side of the table view. Later, we'll modify the app, split the data into sections and add an index list to the table. Well, we're going to organize the data into sections based on the first letter of  With this method, the delegate should change only state-based properties that were set earlier by the table view, such as selection and background color, and not content. Customizing Cells The four predefined styles of UITableViewCell objects suffice for most of the rows that table views display.

Automatically resizing UITableViewCells with Dynamic Type and , We're going to make a UITableView with formatted text that matches a user's preferred size, and Replace it with a new Table View Controller, check its “Is Initial View enumerated(), count, index(of:), property observers, range operators."]) which a way of adding formatting such as fonts, colors and alignment to text, and  The list-style property is a shorthand property. It is used to set all the list properties in one declaration: list-style: square inside url ("sqpurple.gif"); Try it Yourself » When using the shorthand property, the order of the property values are: list-style-type (if a list-style-image is specified, the value of this property will be

Comments
  • The above iteration can be implemented in the method: -(void)viewDidAppear:(BOOL)animated; This will avoid repeating the iteration everytime you scroll the tableView.
  • This method just changed the background color of the indexes for me. What if I want to change the color of fonts only and not their background?
  • @DipDhingani to change the color of the fonts (to red in this example), use this: [view performSelector:@selector(setIndexColor:) withObject:[UIColor redColor]];
  • Since UIKit component view hierarchies have been known to change in the past, if you're going to use this method then I'd recommend searching the whole subview tree (rather than the first level). A recursive way to do so can be found here.
  • [view setFont:[UIFont systemFontOfSize:14]]; setFont not working for me.. How can we set font size
  • Perfect answer! Thanks for this.
  • Perfect... Works like a charm :)
  • Cool. I'm not sure why, but in iOS 8.1, the default index background & text color was blue-on-blue. Thanks to your tip, I could change the "self.tableView.sectionIndexBackgroundColor" to a white background.
  • Works in Swift 5 too