ios11 适配TableView

创建UITableView的类别,将下列代码拷贝进入
/**
 UITableView:适配 iOS 11

 @param tableView tableView description
 */
CG_INLINE void
BAKit_UITableViewAdaptatIOS11(UITableView *tableView)
{
    if (@available(iOS 11.0, *))
    {
        tableView.estimatedRowHeight = 0.f;
        tableView.estimatedSectionHeaderHeight = 0.f;
        tableView.estimatedSectionFooterHeight = 0.f;
    }
}

使用方法

ios11 适配TableView_第1张图片
image.png
if (@available(iOS 11.0, *)) {
        self.baseTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
加上这两句话,会让tableview的内容视图就是frame的大小。默认情况下tableview会自动计算出安全区域,也就是内容视图会从64或20(隐藏导航栏时)开始。

你可能感兴趣的:(ios11 适配TableView)