Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of letters of sectionIndexTitlesForTableView?

Tags:

ios

iphone

ipad

I need to change the color of sectionIndexTitlesForTableView in iOS 5. I could not find any method in the APIs to do the task. Can anyone offer me some help?

The sectionIndexTitlesForTableView means the vertical bar in right hand side to show the the titles for the sections.

Thanks.

like image 253
user403015 Avatar asked Jan 23 '12 11:01

user403015


6 Answers

Swift 3

you can just set the:

tableView.sectionIndexColor 

to whatever color your want like:

tableView.sectionIndexColor = .red
like image 169
ricks Avatar answered Nov 12 '22 11:11

ricks


Go to the IB and change the text COLOR to white, Works for meenter image description here

//=========================================

And in Swift, you can also change Programatically by:

self.my_tableView.sectionIndexColor = UIColor.greenColor()
like image 25
Jasmeet Avatar answered Nov 12 '22 12:11

Jasmeet


Following code is a straight solution. api is available from iOS 6

 [tableView setSectionIndexColor:[UIColor greenColor]];
like image 12
Rajesh Avatar answered Nov 12 '22 11:11

Rajesh


Swift 2.0

The code line below will change the font color of the section index on table view. I have attached the resulting screenshot of the implementation.

self.tblYourTableView.sectionIndexColor = UIColor.redColor()

enter image description here

like image 3
Chamath Jeevan Avatar answered Nov 12 '22 12:11

Chamath Jeevan


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


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



    static NSString *MyIdentifier = @"MyIdentifier";

//***Table cell create

}
like image 2
user2155906 Avatar answered Nov 12 '22 10:11

user2155906


Write Bellow code in your viewDidLoad (for swift)

tableName.sectionIndexColor = UIColor.lightGrayColor()

like image 2
Reema Avatar answered Nov 12 '22 12:11

Reema