UITableView 隱藏最后一條分割線

UITableView 隱藏最后一條分割線-->footerView高度0.1)

ESSeparatorInset分類(lèi)一行代碼搞定

UIView

UIViewController+ESSeparatorInset.h:


// The MIT License (MIT)
//
// Copyright (c) 2015 EnjoySR ( https://github.com/EnjoySR/ESSeparatorInset )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

//
//  UIViewController+ESSeparatorInset.h
//  TableViewSeparatorInset
//
//  Created by  on 15/7/18.
//  Copyright (c) 2015年 EnjoySR. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIViewController (ESSeparatorInset)

- (void)setSeparatorInsetZeroWithTableView:(UITableView *)tableView;

- (void)setSeparatorInsetWithTableView:(UITableView *)tableView inset:(UIEdgeInsets)inset;

/*
 If you want to implement 'tableView:willDisplayCell:forRowAtIndexPath:' for 
 tableview delegate,you should use this method.
 */
- (void)es_tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

@end

UIViewController+ESSeparatorInset.m:

//
//  UIViewController+ESSeparatorInset.m
//  TableViewSeparatorInset
//
//  Created by 尹橋印 on 15/7/18.
//  Copyright (c) 2015年 EnjoySR. All rights reserved.
//

#import "UIViewController+ESSeparatorInset.h"
#import <objc/runtime.h>

static NSString *ES_INSETS_ASS_KEY = @"ES_INSETS_ASS_KEY";

@interface UIViewController()

@property (nonatomic, assign) UIEdgeInsets inset;

@end

@implementation UIViewController (ESSeparatorInset)

+ (void)load
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];
        
        SEL originalSelector = @selector(tableView:willDisplayCell:forRowAtIndexPath:);
        SEL swizzledSelector = @selector(es_tableView:willDisplayCell:forRowAtIndexPath:);
        
        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);
        }
    });
}

- (void)es_tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self respondsToSelector:@selector(es_tableView:willDisplayCell:forRowAtIndexPath:)]) {
        [self es_tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath];
    }
    [self setSeparatorInsetWithTarget:cell insets:self.inset];
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
}

- (void)setSeparatorInsetZeroWithTableView:(UITableView *)tableView{
    [self setSeparatorInsetWithTableView:tableView inset:UIEdgeInsetsZero];
}

- (void)setSeparatorInsetWithTableView:(UITableView *)tableView inset:(UIEdgeInsets)inset{
    self.inset = inset;
    [self setSeparatorInsetWithTarget:tableView insets:inset];
}

- (void)setSeparatorInsetWithTarget:(id)target insets:(UIEdgeInsets)insets{
    if ([target respondsToSelector:@selector(setSeparatorInset:)]) {
        [target setSeparatorInset:insets];
    }
    if ([target respondsToSelector:@selector(setLayoutMargins:)]) {
        [target setLayoutMargins:insets];
    }
}

- (void)setInset:(UIEdgeInsets)insets{
    NSValue *value = [NSValue valueWithUIEdgeInsets:insets];
    objc_setAssociatedObject(self, &ES_INSETS_ASS_KEY, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (UIEdgeInsets)inset{
    NSValue *value = objc_getAssociatedObject(self, &ES_INSETS_ASS_KEY);
    return [value UIEdgeInsetsValue];
}

@end



最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末四敞,一起剝皮案震驚了整個(gè)濱河市洋闽,隨后出現(xiàn)的幾起案子瓶堕,更是在濱河造成了極大的恐慌项炼,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,525評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡孔祸,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)肿嘲,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)融击,“玉大人,你說(shuō)我怎么就攤上這事雳窟∽鹄耍” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,862評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵封救,是天一觀的道長(zhǎng)拇涤。 經(jīng)常有香客問(wèn)我,道長(zhǎng)誉结,這世上最難降的妖魔是什么鹅士? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,728評(píng)論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮惩坑,結(jié)果婚禮上掉盅,老公的妹妹穿的比我還像新娘也拜。我一直安慰自己,他們只是感情好趾痘,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,743評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布慢哈。 她就那樣靜靜地躺著,像睡著了一般永票。 火紅的嫁衣襯著肌膚如雪卵贱。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,590評(píng)論 1 305
  • 那天侣集,我揣著相機(jī)與錄音键俱,去河邊找鬼。 笑死世分,一個(gè)胖子當(dāng)著我的面吹牛编振,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播罚攀,決...
    沈念sama閱讀 40,330評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼党觅,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼雌澄!你這毒婦竟也來(lái)了斋泄?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,244評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤镐牺,失蹤者是張志新(化名)和其女友劉穎炫掐,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體睬涧,經(jīng)...
    沈念sama閱讀 45,693評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡募胃,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,885評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了畦浓。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片痹束。...
    茶點(diǎn)故事閱讀 40,001評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖讶请,靈堂內(nèi)的尸體忽然破棺而出祷嘶,到底是詐尸還是另有隱情,我是刑警寧澤夺溢,帶...
    沈念sama閱讀 35,723評(píng)論 5 346
  • 正文 年R本政府宣布论巍,位于F島的核電站,受9級(jí)特大地震影響风响,放射性物質(zhì)發(fā)生泄漏嘉汰。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,343評(píng)論 3 330
  • 文/蒙蒙 一状勤、第九天 我趴在偏房一處隱蔽的房頂上張望鞋怀。 院中可真熱鬧双泪,春花似錦、人聲如沸密似。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,919評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)辛友。三九已至薄扁,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間废累,已是汗流浹背邓梅。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,042評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留邑滨,地道東北人日缨。 一個(gè)月前我還...
    沈念sama閱讀 48,191評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像掖看,于是被迫代替她去往敵國(guó)和親匣距。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,955評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容