最近为了适配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
网友评论