控件處理之左滑cell

UITableView自定義系統(tǒng)左滑Cell菜單

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

? ? if (editingStyle == UITableViewCellEditingStyleDelete) {

? ? }

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

? ? return UITableViewCellEditingStyleDelete;

}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {

? ? return @"標(biāo)記為\n已回訪";

}

// 設(shè)置顯示多個(gè)按鈕

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

? ? UITableViewRowAction * deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"屏蔽用戶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

? ? }];

? ? deleteRowAction.backgroundColor = [UIColor redColor];

? ? UITableViewRowAction * topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"取消關(guān)注" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

? ? }];

? ? topRowAction.backgroundColor = [UIColor blueColor];

? ? return @[deleteRowAction,topRowAction];

}

在cell中自定義樣式

- (void)layoutSubviews

{

? ? [super layoutSubviews];

? ?

? ? // 去掉隱式動(dòng)畫

? ? [CATransaction begin];

? ? [CATransaction setDisableActions:YES];

? ? [self setupSlideBtn];

? ? [CATransaction commit];

}

// 設(shè)置左滑菜單按鈕的樣式

- (void)setupSlideBtn

{

? ? for (UIView *subView in self.subviews) {

? ? ? ? if([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {

? ? ? ? ? ?

? ? ? ? ? ? // 屏蔽用戶

? ? ? ? ? ? UIView *smsContentView = subView.subviews[0];

? ? ? ? ? ?

? ? ? ? ? ?

? ? ? ? ? ? for (UIView *smsView in smsContentView.subviews) {

? ? ? ? ? ? ? ? [smsView removeAllSubviews];

? ? ? ? ? ? }

? ? ? ? ? ?

? ? ? ? ? ? UIImageView *smsImage = [[UIImageView alloc] init];

? ? ? ? ? ? smsImage.image = [UIImage imageNamed:@"UserView_follow2"];

? ? ? ? ? ? smsImage.frame = smsContentView.bounds;

? ? ? ? ? ? [smsContentView addSubview:smsImage];

? ? ? ? ? ?

? ? ? ? ? ?

? ? ? ? ? ? // 取消關(guān)注

? ? ? ? ? ? UIView *messageContentView = subView.subviews[1];

? ? ? ? ? ?

? ? ? ? ? ? for (UIView *messageView in messageContentView.subviews) {

? ? ? ? ? ? ? ? [messageView removeAllSubviews];

? ? ? ? ? ? }

? ? ? ? ? ?

? ? ? ? ? ? UIImageView *messageImage = [[UIImageView alloc] init];

? ? ? ? ? ? messageImage.image = [UIImage imageNamed:@"UserView_follow1"];

? ? ? ? ? ? messageImage.frame = messageContentView.bounds;

? ? ? ? ? ? [messageContentView addSubview:messageImage];

? ? ? ? ? ?

? ? ? ? }

? ? }

}

使用panCell自定義左滑菜單

1、創(chuàng)建 cell 繼承 PanTableViewCell?

2、添加PanTableViewCellDelegate協(xié)議方法

3、實(shí)現(xiàn)協(xié)議方法

#import "PanCellButton.h"

- (NSArray<PanCellButton *> *)panTableViewCell:(PanTableViewCell *)cell tableView:(UITableView *)tableView rightPanCellButtonsAtIndexPath:(NSIndexPath *)indexPath{

? ?

? ? PanCellButton *removeFollowUserButton = [[PanCellButton alloc] initWithTitle:nil image:[UIImage imageNamed:@"UserView_follow1"] onClickCallback:^(UIButton *panButton) {

? ? ? ? [self CancelFollowAction];

? ? }];

? ?

? ? PanCellButton *hiddenUserButton = [[PanCellButton alloc] initWithTitle:nil image:[UIImage imageNamed:@"UserView_follow2"] onClickCallback:^(UIButton *panButton) {

? ? ? ? [self ShieldingUser];

? ? }];

? ?

? ? return @[hiddenUserButton,removeFollowUserButton];

}

效果圖

菜單的大小可以自定義

下載使用

https://github.com/githubze/panCell

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1.nav1.navigationBar.barStyle=UIBarStyleBlack; //改變導(dǎo)航欄背景顏...
    SadMine閱讀 1,875評(píng)論 1 4
  • *7月8日上午 N:Block :跟一個(gè)函數(shù)塊差不多,會(huì)對(duì)里面所有的內(nèi)容的引用計(jì)數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,752評(píng)論 1 14
  • 版權(quán)聲明:未經(jīng)本人允許,禁止轉(zhuǎn)載. 1. TableView初始化 1.UITableView有兩種風(fēng)格:UITa...
    蕭雪痕閱讀 2,993評(píng)論 2 10
  • 一群人像一股胡亂頹圮的色彩融入了黑白分明的大綱,從進(jìn)門那一刻橘右京就開(kāi)始恍惚起來(lái)。 人是從什么時(shí)候有恍惚這種感覺(jué)的...
    丁二二丁閱讀 383評(píng)論 0 1
  • 平時(shí)很少去醫(yī)院,倒不是身體多好,是嫌麻煩。沒(méi)想到去了一趟醫(yī)院,發(fā)生很多麻煩事。 這幾個(gè)月鼻炎越來(lái)越嚴(yán)重,朋友嚴(yán)正警...
    傲骨前妻閱讀 271評(píng)論 0 1

友情鏈接更多精彩內(nèi)容