iOS11设备上tableview分割线的问题

最近为了适配iOS 11,碰到一些问题。现在ipa基于iOS SDK 9 运行在iOS11.1上发现tableview的分割线不能订到两边。查阅资料特将解决办法分享一下!
//
// UITableView+NASeparatorInset.m
// iPoS_IOS
//
// Created by Jason on 17/11/7.
// Copyright © 2017年 Treasure Frontier System Sdn. Bhd. All rights reserved.
//

import "UITableView+NASeparatorInset.h"

import <objc/runtime.h>

@implementation UITableView (NASeparatorInset)

  • (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
    Class class = [self class];

      SEL originalSelector = @selector(initWithFrame:style:);
      SEL swizzledSelector = @selector(initWithNAFrame:style:);
      
      Method originalMethod = class_getInstanceMethod(class, originalSelector);
      Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
      
      BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
      if (success) {
          class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
      } else {
          method_exchangeImplementations(originalMethod, swizzledMethod);
      }
    

    });
    }

  • (instancetype)initWithNAFrame:(CGRect)frame style:(UITableViewStyle)style{
    UITableView *tableView=nil;

    if ([self respondsToSelector:@selector(initWithNAFrame:style:)]) {
    tableView= [self initWithNAFrame:frame style:style];
    }
    if([tableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)])
    {
    tableView.cellLayoutMarginsFollowReadableWidth = NO;
    }
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
    [tableView setLayoutMargins:UIEdgeInsetsZero];
    }

    return tableView;

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转载:http://www.cocoachina.com/ios/20161102/17920.html 因为Ob...
    F麦子阅读 3,836评论 0 1
  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 4,799评论 1 6
  • 本文转载自:http://yulingtianxia.com/blog/2014/11/05/objective-...
    ant_flex阅读 4,162评论 0 1
  • 转载:http://yulingtianxia.com/blog/2014/11/05/objective-c-r...
    F麦子阅读 4,101评论 0 2
  • 氧化:臭氧注入椎间盘后能迅速氧化髄核内的蛋白多糖,使髄核细胞模和细胞内结构破坏,造成细胞变性坏死,细胞合成和分泌蛋...
    颖茜阅读 1,683评论 0 1