How to resize UITableView in UITableViewController with section header

后端 未结 5 1135
情话喂你
情话喂你 2020-12-29 13:14

I\'ve got a grouped UITableView in a UITableViewController and I want to resize it horizontally.

I tried many different ways but none of them was perfect.

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-29 13:46

    To fix the headers being resized I would try:

    - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        CGFloat headerHeight = 40;
        UIView *headerView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, headerHeight)];
        UILabel *cellLabel = [[UILabel alloc] initWithFrame: headerView.frame];
        [cellLabel setText: @"My Text"];
        [cellLabel setBackgroundColor: [UIColor clearColor]];
        [headerView addSubview: cellLabel];
        return headerView;
    }
    
        - (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 40;
    }
    

    This code should replace this method:

    - (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    

提交回复
热议问题