Friday, June 7, 2013

UITableView sectionIndexTrackingBackgroundColor example in Objective C (iOS).


UITableView sectionIndexTrackingBackgroundColor

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

@property(nonatomic, retain) UIColor *sectionIndexTrackingBackgroundColor

Discussion of [UITableView 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.

UITableView sectionIndexTrackingBackgroundColor example.
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 the scrubber.

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

Example of [UITableView sectionIndexTrackingBackgroundColor].
if ([_tableView respondsToSelector: @selector(setSectionIndexColor: )])  ////ios6
    {
        self.tableView.sectionIndexColor = [UIColor whiteColor];
        self.tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];
    }
    else
    {
       /*
        for(UIView *view in [self.tableView subviews])
        {
            if([view respondsToSelector: @selector(setIndexColor:  )])
            {
                [view performSelector: @selector(setIndexColor: ) withObject:[UIColor redColor]];
                [view performSelector: @selector(setIndexBackgroundColor: ) withObject:[UIColor clearColor]];
            }
        }
        //*/
    }

End of UITableView sectionIndexTrackingBackgroundColor example article.