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

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

Loading...

(Visited 1 times, 1 visits today)