更改UITable Section Title颜色

时间:2010-09-15 07:05:15

标签: iphone ios uitableview

我想更改UITableView节标题的颜色。

2 个答案:

答案 0 :(得分:6)

使用以下代码作为答案

-(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;
}

这将为您提供一个redColor标头。根据您的要求更改颜色......

已编辑(根据严苛考验):

由于标题中的视图将与您的第一个单元格重叠,因此请增加标题的高度

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

hAPPY cODING ........

答案 1 :(得分:1)

使用- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 此方法是UITableViewDelegate的一部分 返回带有标签的视图。您现在可以配置标签颜色。