我的iOS11及iPhoneX适配(二)

继昨天适配iOS11修改部分问题后,发现其实很多页面都用了UITableView,这个肯定不能每个页面都一个个的修改,于是决定写一个BaseUITableView,然后把目前用到UITableView的地方都换为BaseUITableView,代码如下:

- (instancetype)init

{

    if (self = [super init])

    {

        [self dismissSomePropertyForiOS11];

    }

    return self;

}


- (instancetype)initWithFrame:(CGRect)frame

{

    if (self = [super initWithFrame:frame])

    {

        [self dismissSomePropertyForiOS11];

    }

    return self;

}


- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style

{

    if (self = [super initWithFrame:frame style:style])

    {

        [self dismissSomePropertyForiOS11];

    }

    return self;

}


- (instancetype)initWithCoder:(NSCoder *)aDecoder

{

    if (self = [super initWithCoder:aDecoder])

    {

        [self dismissSomePropertyForiOS11];

    }

    return self;

}


- (void)dismissSomePropertyForiOS11

{

    //如果iOS的系统是11.0,会有这样一个宏定义“#define __IPHONE_11_0  110000”;如果系统版本低于11.0则没有这个宏定义

#ifdef __IPHONE_11_0

    if ([self respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)])

    {

        self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

    }

#endif

    

    self.estimatedRowHeight = 0;

    self.estimatedSectionHeaderHeight = 0;

    self.estimatedSectionFooterHeight = 0;

}


然后在调用的地方都替换为:

UITableView *tableView = [[BaseUITableView alloc] init];


或者

_taskTabelView  = [[BaseUITableView alloc]initWithFrame:CGRectMake(0,0, DEVICE_WIDTH, DEVICE_HEIGHT) style:UITableViewStyleGrouped];


最后在

PrefixHeader.pch

文件加上:

#import "BaseUITableView.h"


完成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值