iOS 自定义cell侧滑删除、编辑等按钮
来源:互联网 发布:java上传文件到本地 编辑:程序博客网 时间:2024/06/03 09:50
iOS自定义cell侧滑删除、编辑等按钮,用的是一个网上大神封装好的类,直接引用,就ok了,简单粗暴,适配支持iOS9.2、Xcode7.2
要下载源码的请猛戳这里下载
下面是效果图
ViewController.m中得方法
//// ViewController.m// cell侧滑demo//// Created by renjinbo on 15/12/28.// Copyright © 2015年 com.coffee.biggerapple.zxp. All rights reserved.//#import "ViewController.h"#import "SMMoreOptionsCell.h"//使用时候直接将 SMMoreOptionsCell 两个类拖到工程中即可@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,SMMoreOptionsDelegate>@property (nonatomic, strong) UITableView *tabelViewDemo;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.tabelViewDemo = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds]; self.tabelViewDemo.delegate = self; self.tabelViewDemo.dataSource = self; [self.view addSubview:self.tabelViewDemo];}-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 10;}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"cell"; SMMoreOptionsCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell) { cell = [[SMMoreOptionsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } //代理 cell.delegate = self; cell.scrollViewOptionsWidth = 150; UIView *extraView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 150, 60)]; [cell.scrollViewOptionsView addSubview: extraView]; UILabel *contenLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60)]; contenLable.text = @"向右滑动试试会有惊喜"; [cell.scrollViewContentView addSubview:contenLable];//此处文字必须用scrollViewContentView,且用添加子视图的形式添加 //侧滑出现的自定义button extraView.backgroundColor = [UIColor redColor]; UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeSystem]; deleteBtn.frame = CGRectMake(0, 0, 75, 60); deleteBtn.backgroundColor = [UIColor lightGrayColor]; [deleteBtn setImage:[UIImage imageNamed:@"模板编辑_删除"] forState:UIControlStateNormal]; [deleteBtn addTarget:self action:@selector(clickDelete) forControlEvents:UIControlEventTouchUpInside]; [extraView addSubview:deleteBtn]; UIButton *editBtn = [UIButton buttonWithType:UIButtonTypeSystem]; editBtn.frame = CGRectMake(75, 0, 75, 60); editBtn.backgroundColor = [UIColor orangeColor]; [editBtn setImage:[UIImage imageNamed:@"联系人_编辑icon"] forState:UIControlStateNormal]; [extraView addSubview:editBtn]; return cell;}-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 60;}-(void)clickDelete{ NSLog(@"删除成功");}#pragma mark - SMMoreOptionsDelegate- (void)didTouchOnDelete:(SMMoreOptionsCell *)cell {}- (void)didTouchOnMore:(SMMoreOptionsCell *)cell {}- (void)cellDidHideOptions:(SMMoreOptionsCell *)cell {}- (void)cellDidShowOptions:(SMMoreOptionsCell *)cell {}@end
SMMoreOptionsCell.h的代码
//// SMMoreOptionsCell.h// SMMoreOptionsCell//// Created by Richard Marktl (@richmarktl) on 23.08.13.// Copyright (c) 2013 Richard Marktl (@richmarktl). All rights reserved.////#import <UIKit/UIKit.h>@protocol SMMoreOptionsDelegate;////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////@interface SMMoreOptionsCell : UITableViewCell@property (nonatomic, strong) UIView *scrollViewContentView; // This content view is above the more options view.// This scrollViewOptionsView contains per default the following 2 buttons, feel free to set your own options view. In// the case you set your own custom scrollViewOptionsView, the -didTouchOnDelete: and -didTouchOnMore: are not called.// The options view is always set to hidden if not visible through the scroll behaviour.@property (nonatomic, strong) UIView *scrollViewOptionsView;@property (nonatomic, strong) UIButton *moreButton; // set your own button or modify the existing button@property (nonatomic, strong) UIButton *deleteButton; // set your own button or modify the existing button@property (nonatomic, assign) CGFloat scrollViewOptionsWidth; // set width of the scrollViewOptionsView, default 150 px@property (nonatomic, weak) id<SMMoreOptionsDelegate> delegate;- (void)dismissOptionsAnimated:(BOOL)animated; // in the case the options are visble the view will dismiss them@end////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////@protocol SMMoreOptionsDelegate <NSObject>@required- (void)didTouchOnDelete:(SMMoreOptionsCell *)cell;- (void)didTouchOnMore:(SMMoreOptionsCell *)cell;@optional- (void)cellDidHideOptions:(SMMoreOptionsCell *)cell;- (void)cellDidShowOptions:(SMMoreOptionsCell *)cell;@end////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////@interface UIImage (SMMoreOptionsCell)+ (UIImage *)imageWithColor:(UIColor *)color;@end////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////extern const CGFloat SMMoreOptionsDefaultContentWidth;extern NSString * const SMMoreOptionsShouldHideNotification; // post this notification to hide currently visible options
0 0
- iOS 自定义cell侧滑删除、编辑等按钮
- iOS自定义按钮删除Cell
- iOS 8自定义cell的删除按钮
- iOS8自定义cell的删除按钮、更多、置顶等按钮的样式
- tableView cell 左滑点击删除等点击按钮
- iOS 自定义等高cell
- 自定义searchview的编辑框,搜索按钮,删除按钮,光标等
- 自定义tableView cell的删除按钮
- ios表格cell的编辑和删除
- 【iOS学习笔记 15-12-19】自定义cell侧滑按钮(UIButton)
- iOS项目开发小技巧 (三) --UITableView实现Cell左划删除等自定义功能
- iOS开发中实现UITableView的Cell左划删除等自定义功能
- iOS UITableViewCell (左滑删除按钮及编辑模式)
- UITableView 自带编辑删除 自定义按钮
- UITableView 自带编辑删除 自定义按钮
- ios tableview cell 侧滑删除
- iOS 自定义cell高度(非等高)
- IOS开发-15.自定义cell(等高cell)
- 求字符串所有的排列方式
- BZOJ-1189 紧急疏散evacuate BFS预处理+最大流+二分判定+神建模!!
- 讨论一下你们心目中的最优秀的Ajax框架是什么?
- Codeforces Round #335 (Div. 2) C. Sorting Railway Cars
- Codeforces Round #335 (Div. 2) B. Testing Robots
- iOS 自定义cell侧滑删除、编辑等按钮
- #Objective - C - UI-design - 第五天 -UIKit框架-UIKit-Catalog-UIControl
- linux 添加用户、权限
- nyoj999
- 组播技术
- 实现折叠的uitableviewcell效果
- iOS中UIStackView相关属性理解
- Fragment 初学
- Swift学习之Playground