tags:

views:

124

answers:

2

I need to change the co9lor of title of UITable section. Help need urgrntly

+1  A: 

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.

Satyam svv
Hi Satyam I used this method and it worked for me.
Harsh
+1  A: 

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...

Suriya
both tempView and tempLabel should really be autoreleased in this code.
zem
thanks zem for pointing out.. As i have wriiten the code directly over here so have forgot. Also Please set the frames as per your convinience...
Suriya
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 50;}
Harsh
Thanks Suriya but I found that one should also use ablove function to set the height of the section header otheraise the header name will be overlapped with the table cell.
Harsh
Yes the height must be greater than the views size..I have edited and added that too in the answer `Getting a vote is the best thanks...`
Suriya