Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customising the font/background colour of index/section bar in UITableView

Tags:

I've read in another thread on SO that you can adjust the font or background colour of the index bar (that is the A-Z # scrollbar) in a UITableView adding a CALayer. My app will be running on iOS 5 and above and since I haven't seen anything about this in the Apple docs, would it be right to say that it simply isn't possible without creating a custom table view?

If this is possible (and acceptable to Apple), how would I go about doing this?

like image 808
sooper Avatar asked Nov 07 '12 17:11

sooper


1 Answers

As of iOS 6.0 there are two methods that allow you to change the color of the section indexes and the background shown when you drag along the section indexes.

if ([tableView respondsToSelector:@selector(setSectionIndexColor:)]) {
    tableView.sectionIndexColor = ... // some color
    tableView.sectionIndexTrackingBackgroundColor = ... // some other color
}

Of course this will only execute if the device has 6.0 or later. Under iOS 5.x, nothing will change.

like image 196
rmaddy Avatar answered Sep 28 '22 03:09

rmaddy