iOS 不同版本特性及适配(iOS 8 ~ iOS 16)

iOS 15:

一、tableview 默认顶部增加一段空白高度

​ 这是因为 plain 类型的 UITableView 增加默认的 section 高度,也就是 UITableView 增加了一个新属性:sectionHeaderTopPadding,默认值为automaticDimension,当我们使用UITableViewStylePlain 初始化tableView的时候,sectionHeaderTopPadding 会给 section header 默认增加高度,解决方案是把 sectionHeaderTopPadding 属性设置为0即可:

if (@available(iOS 15.0, *)) { 
  tableView.sectionHeaderTopPadding = 0;
}
二、UINavigationBar默认是透明问题

​ 在iOS15中,UINavigationBar默认是透明的,向上滑动时会逐渐变为模糊效果,可以通过改变scrollEdgeAppearance属性直接变为模糊效果,代码如下:

if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
        navBar.scrollEdgeAppearance = appearance;
 }
三、TabBar透明问题

​ iOS15中,UITabBar默认背景是透明的,向下滑动是背景会显示出来,可以通过改变scrollEdgeAppearance属性直接显示出来背景色,代码如下:

if (@available(iOS 15.0, *)) {
   self.tabBar.scrollEdgeAppearance = tabBarAppearance;
}

iOS 11:

一、iOS 11,UITableView Header、Footer高度设置不起作用问题

  iOS 11 之后设置 UITableView 的 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;这个方法根本没效果。而且会默认有个 Header 大概20的高度,解决办法:实现 UITableView 的另外两个代理方法即可:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {            
  return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  return nil;
}
持续更新中。。。
posted @ 2021-09-23 15:50  小码哥伍六七  阅读(2240)  评论(0编辑  收藏  举报