-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 38)] autorelease];
// [headerView setBackgroundColor:[UIColor colorWithRed:149/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]];
//
// return headerView;
UILabel *headerLabel = [[[UILabel alloc]initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width,38)]autorelease];
if (section == 0) {
headerLabel.text = @"headAAAAAAA";
}
else {
headerLabel.text = @"headBBBBBBB";
}
//[headerLabel setFont:[UIFont fontWithName:@"Helvetica" size:18.0]];
[headerLabel setFont:[UIFont boldSystemFontOfSize:18.0]];
[headerLabel setTextColor:[UIColor whiteColor]];
[headerLabel setBackgroundColor:[UIColor clearColor]];
return headerLabel;
}
下面这个函数仅仅是设置head的title...
-(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return @"headAAAAAAA";
}
else {
return @"headBBBBBBB";
}
}
本文介绍了一种方法来改善UITableView头部视图的颜色显示效果。通过重写tableView:viewForHeaderInSection方法,可以创建自定义的UILabel作为头部视图,并设置字体、文字颜色等属性。
2177

被折叠的 条评论
为什么被折叠?



