UITableView侧滑添加多个效果以及修改颜色
2016-04-07 16:20
369 查看
1. 首先创建UITableView视图,实现其俩个代理,UITableViewDelegate和UITableViewDataSource,该处代码就不说了,主要是俩个回调方法
和
2. 然后实现另一个代理方法
3. 再实现
`-(NSArray )tableView:(UITableView )tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@”删除” handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {//title可自已定义
NSLog(@”点击删除”);
}];//此处是iOS8.0以后苹果最新推出的api,UITableViewRowAction,Style是划出的标签颜色等状态的定义,这里也可自行定义
}`
这样就实现了如下的效果
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
和
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
2. 然后实现另一个代理方法
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { editingStyle = UITableViewCellEditingStyleDelete;//此处的EditingStyle可等于任意UITableViewCellEditingStyle,该行代码只在iOS8.0以前版本有作用,也可以不实现。 }
3. 再实现
`-(NSArray )tableView:(UITableView )tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@”删除” handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {//title可自已定义
NSLog(@”点击删除”);
}];//此处是iOS8.0以后苹果最新推出的api,UITableViewRowAction,Style是划出的标签颜色等状态的定义,这里也可自行定义
UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal
title:@"编辑" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { }]; editRowAction.backgroundColor = [UIColor colorWithRed:0 green:124/255.0 blue:223/255.0 alpha:1];//可以定义RowAction的颜色 return @[deleteRoWAction, editRowAction];//最后返回这俩个RowAction 的数组
}`
这样就实现了如下的效果
相关文章推荐
- UIImagePickerController 浅析
- 工程中报错或者警告一些情况及解决办法。例如:does not contain bitcode. You must rebuild it with bitcode enabled
- Errors running builder 'DeploymentBuilder' on project_java
- ueditor
- 解决:Failed to create 'build\outputs\apk\watch-debug-unaligned.apks': 拒绝访问。
- 你真的会用UITableView嘛
- 苹果官方xcode工程build设置指南
- UGUI 下拉滚动框
- 解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误
- 优化UITableViewCell高度计算的那些事
- UITableViewCell高度自适应探索--AutoLayout结合Frame
- IOS开发-UI学习-NSMutableAttributedString(带属性的字符串)的使用
- iOS开发基础学习笔记——导航控制器2->导航栏(UINavigationBar)/工具栏(toolBar)/导航元素按钮(UINavigationItem)
- easyui的datagrid的分页问题
- UITableView优化技巧
- 一个实现 Twitter SnowFlake 算法 的 Go 分布式 UID 生成器
- 改变UITextView的边框颜色
- UIView的contentMode使用小结
- 自定义UICollectionViewLayout(一) ----LineLayout
- UITextField小结