我想更改UITableView节标题的颜色。
答案 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的一部分
返回带有标签的视图。您现在可以配置标签颜色。