How to set the height of table header in UITableView?

前端 未结 17 1411
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 22:00

I have gone through Apple docs about UITableView class and delegate reference but couldn\'t find the way to set the table header height explicitly.

I set Table cell

17条回答
  •  情书的邮戳
    2020-12-02 22:44

    @kris answer is helpful for me anyone want it in Objective-C.

    Here is the code

    -(void)viewDidLayoutSubviews{
         [super viewDidLayoutSubviews];
         [self sizeHeaderToFit];
    }
    
    -(void)sizeHeaderToFit{
         UIView *headerView = self.tableView.tableHeaderView;
         [headerView setNeedsLayout];
         [headerView layoutIfNeeded];
         CGFloat height = [headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
         CGRect frame = headerView.frame;
         frame.size.height = height;
         headerView.frame = frame;
         self.tableView.tableHeaderView = headerView;
    }
    

提交回复
热议问题