今天来给大家介绍下iOS开发中UITableView左滑实现微信中置顶,删除等功能。对大家开发iOS具有一定的参考借鉴价值,有需要的朋友们一起来看看吧。
前言
相信每位iOS开发者都知道UITableView的左滑删除功能非常的炫酷,有时候左滑需要的功能不止只有删除一个,有时候会有顶置之类的别的功能,这时候就需要我们自己定制左滑
示例代码
-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"取消收藏" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
NSLog(@"收藏点击事件");
}];
UITableViewRowAction *rowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
title:@"顶置" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
NSLog(@"顶置按钮点击事件");
}];
rowAction.backgroundColor =RGB(215, 59, 16);
NSArray *arr = @[rowAction,rowAction2];
return arr;
}
总结
我们可以利用UITableViewRowAction 创建对象,后面的代码块就是点击后执行的方法,创建完的对象加到数组中,这样的话我们就可以随意定制,颜色我们也可以自己选择,非常的方便。以上就是这篇文章的全部内容,希望能对大家的学习或者工作带来一定的帮助,如果有疑问大家可以留言交流。
沃梦达教程
本文标题为:iOS开发之UITableView左滑删除等自定义功能


猜你喜欢
- Android实现轮询的三种方式 2023-02-17
- Android实现监听音量的变化 2023-03-30
- Android studio实现动态背景页面 2023-05-23
- 详解flutter engine 那些没被释放的东西 2022-12-04
- iOS 对当前webView进行截屏的方法 2023-03-01
- 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- Flutter实现底部和顶部导航栏 2022-08-31