之前一直以為設(shè)置-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section和-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section腊敲;就行了博个。在iOS15以下的版本沒問(wèn)題东揣,但是發(fā)現(xiàn)在iOS15以上還是會(huì)有20的像素高度晌涕。困擾了好長(zhǎng)時(shí)間盆偿。后來(lái)查閱資料才知道,iOS15新增了屬性。
?iOS 15 的 UITableView又新增了一個(gè)新屬性:sectionHeaderTopPadding 會(huì)給每一個(gè)section header 增加一個(gè)默認(rèn)高度
當(dāng)我們 使用 UITableViewStylePlain 初始化 UITableView的時(shí)候,就會(huì)發(fā)現(xiàn)刚陡,系統(tǒng)給section header增高了22像素。
//解決辦法
? ? if (@available(iOS 15.0, *)) {
?? ? ? self.tableView.sectionHeaderTopPadding = 0;
? ? }