Change UITable section backgroundColor without loosing section Title

前端 未结 5 2151
北海茫月
北海茫月 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:51

    We have a better solution for this from iOS6 onwards:

    There is a delegate method

    - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section

    You can use this method like this

    -(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    
         //Set the background color of the View
         view.tintColor = [UIColor blueColor];
    
         // Text Color
         UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
         [header.textLabel setTextColor:[UIColor whiteColor]];
    
    }
    

提交回复
热议问题