Change UITable section backgroundColor without loosing section Title

前端 未结 5 2161
北海茫月
北海茫月 2020-12-15 00:57

i have changed the backgroundColor/backgroundImage of my tableviews sections.
I am using plain tableView. No worries, get worked without problems with this code:

5条回答
  •  情话喂你
    2020-12-15 01:43

    ~Best Solution iPhone 3.5 and 4 screen~

    Set the back color or background image from this code. Here you don't have to calculate for section height, just set in xib.

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
        
        UIView *sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width,tableView.sectionHeaderHeight)];
        sectionView.backgroundColor = [UIColor greenColor];
        
        return sectionView;
    }
    

提交回复
热议问题