您的位置:首页 > 产品设计 > UI/UE

UITableView侧滑添加多个效果以及修改颜色

2016-04-07 16:20 369 查看
1. 首先创建UITableView视图,实现其俩个代理,UITableViewDelegate和UITableViewDataSource,该处代码就不说了,主要是俩个回调方法

-(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 的数组


}`

这样就实现了如下的效果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: