UITableView - change section header color

前端 未结 30 2880
不思量自难忘°
不思量自难忘° 2020-11-27 08:50

How can I change color of a section header in UITableView?

EDIT: The answer provided by DJ-S should be considered for iOS 6 and above. The accepted

30条回答
  •  野性不改
    2020-11-27 09:32

    Here's how to add an image in header view:

    - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
    {
        UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
        UIImageView *headerImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top-gery-bar.png"]] autorelease];
    
        headerImage.frame = CGRectMake(0, 0, tableView.bounds.size.width, 30);
    
        [headerView addSubview:headerImage];
    
        return headerView;
    }
    

提交回复
热议问题