简单适配iOS 11和iPhone X

这篇博客介绍了如何在Swift和Objective-C中适配iOS 11,包括设置UIScrollView的内容 inset 调整行为以及处理tableView在iOS 11上可能出现的section头部和尾部间隙问题。同时,还提供了针对iPhone X的屏幕适配建议,如配置全屏启动图以及调整tableView headerView和footerView的高度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

适配iOS 11:

    Swift : 

                if #available(iOS 11.0,*){

                    UIScrollView.appearance().contentInsetAdjustmentBehavior = .never

                } else {

                    self.automaticallyAdjustsScrollViewInsets = false

                }

                使用tableView时 如果出现section头部或尾部间隙过大时,可以对tableView的属性做修改

                if #available(iOS 11.0,*){

                    tableView.estimatedSectionFooterHeight = 0.01

                    tableView.estimatedSectionHeaderHeight = 0.01

                } 

                   

    OC :

              if (@available (iOS 11.0, *)) {

                    [[UIScrollView appearance]  setContentInsetAdjustmentBehavior: UIScrollViewContentInsetAdjustmentNever];

              } else {

                    self.automaticallyAdjustsScrollViewInsets = NO;

              }

              //对于tableView

               if (@available (iOS 11.0, *)){

                    tableView.estimatedSectionFooterHeight = 0.01

                    tableView.estimatedSectionHeaderHeight = 0.01

                } 

 

  iPhone X简单适配:

          配置全屏(1125x2436)的启动图(launchImage)

          部分app可能会出现tableView的headerView或者footerView过大,需要实现DataSource中如下方法

          - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

          - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

              

                

              

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值