美文网首页
iOS11设备上tableview分割线的问题

iOS11设备上tableview分割线的问题

作者: Jason_KB | 来源:发表于2017-11-07 17:28 被阅读0次

最近为了适配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

相关文章

网友评论

      本文标题:iOS11设备上tableview分割线的问题

      本文链接:https://www.haomeiwen.com/subject/ocijmxtx.html