1

My app looks just like the default address book app on iphone. For each alphabet there is a section header in the address book( A, B . .) in gray gradient background color. Is it possible to override that default color to some other tint color ?

2 Answers 2

4
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { // create the parent view that will hold header Label UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 25.0)]; // create the button object UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero]; headerLabel.backgroundColor = [UIColor blackColor]; headerLabel.opaque = NO; headerLabel.textColor = [UIColor whiteColor]; headerLabel.highlightedTextColor = [UIColor whiteColor]; headerLabel.font = [UIFont boldSystemFontOfSize:20]; headerLabel.frame = CGRectMake(0.0, 0.0, 320.0, 22.0); // If you want to align the header text as centered //headerLabel.frame = CGRectMake(150.0, 0.0, 300.0, 44.0); headerLabel.text = @"Name of header"; [customView addSubview:headerLabel]; return customView; } 
Sign up to request clarification or add additional context in comments.

Comments

1

You can replace the section headers of a UITableView by implementing the following method in the UITableViewDelegate:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

You will probably also want to implement the height method to ensure your new section view displays correctly :

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

To change the colour of the section header, create a UIView with a UIImageView within it, and a UILabel for the text of the section. Add an image to the UIImageView for how you want the background to look.

AFAIK, you can't manipulate the tintColor of the section view.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.