Developer
Developer

Reputation: 6465

Change UITable Section Title color

I want to change the color of UITableView section header.

Upvotes: 1

Views: 4719

Answers (2)

Suresh Varma
Suresh Varma

Reputation: 9740

Use the below code for your answer

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
 UIView *tempView=[[[UIView alloc]initWithFrame:CGRectMake(0,0,300,44)]autorelease];
 tempView.backgroundColor=[UIColor redColor];
 UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0,300,44)];
 tempLabel.backgroundColor=[UIColor clearColor];
 tempLabel.text=@"MY HEADER";
 [tempView addSubview: tempLabel];
 [tempLabel release];
 return tempView;
}

This will give you a redColor header. Change the color as per your requirement...

Edited (as per Harsh):

Since the view in header will overlap your First cell so increase the height of the header

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{ 
return 50; 
} 

hAPPY cODING........

Upvotes: 6

Satyam
Satyam

Reputation: 15894

Use - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section This method is part of UITableViewDelegate Return the view with label. you can now configure label color.

Upvotes: 1

Related Questions