Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change font color of section index titles

I want to display an indexed table view.

By default, section index titles have gray color.

How do I change their color?

like image 695
Abhinav Batra Avatar asked Jul 12 '11 09:07

Abhinav Batra


3 Answers

EDIT/FOLLOW UP iOS7 (Sept. 2013) Read answer of Graham Perks for a follow up on iOS7 where he explains about sectionIndexTrackingBackgroundColor and sectionIndexBackgroundColor


Follow up (Sept. 2012) of this question for future readers.

Since iOS 6 it is now possible to change the index color text and background. Two functions are available for that (see iOS 6 documentation).


sectionIndexColor

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

@property(nonatomic, retain) UIColor *sectionIndexColor

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.

Availability : Available in iOS 6.0 and later.

Declared In : UITableView.h


sectionIndexTrackingBackgroundColor

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

@property(nonatomic, retain) UIColor *sectionIndexTrackingBackgroundColor

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 display in the background of the index when the user drags a finger through it.

Availability : Available in iOS 6.0 and later.

Declared In : UITableView.h

like image 96
HpTerm Avatar answered Oct 05 '22 14:10

HpTerm


Add the below code in your viewDidLoad (for swift):

tableView.sectionIndexColor = UIColor.lightGrayColor()
like image 15
Reema Avatar answered Oct 05 '22 14:10

Reema


In iOS 7, to change the normal background color use the sectionIndexBackgroundColor property.

sectionIndexTrackingBackgroundColor is the background color while tracking with your finger.

(Thanks to HpTerm for the initial pointers which work great on iOS 6.)

like image 13
Graham Perks Avatar answered Oct 05 '22 14:10

Graham Perks