20

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?

sooper
  • 5,991
  • 6
  • 40
  • 65

3 Answers3

43

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 16
    There's also sectionIndexBackgroundColor which I believe used to default to clear, and is now set to a grayish color under iOS7. – Eli Burke Sep 25 '13 at 19:22
5

Here is code for swift 2+

self.tableView.sectionIndexTrackingBackgroundColor = CustomColor
// background color while the index view is being touched
self.tableView.sectionIndexBackgroundColor = CustomColor
// title/text color of index items 
self.tableView.sectionIndexColor = CustomColor
Rafat touqir Rafsun
  • 2,777
  • 28
  • 24
0

For Swift 3.1:

 self.tblViewForContacts.sectionIndexTrackingBackgroundColor = self.view.backgroundColor
 self.tblViewForContacts.sectionIndexBackgroundColor = self.view.backgroundColor
Ankit Goyal
  • 3,019
  • 1
  • 21
  • 26