QQ左滑出现3个点击框的方法

这方法iOS8才出的,老是忘,还是记录一下吧

// 写这一个方法,自动进入编辑模式,出现左滑效果
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // UITableViewRowAction创建了活动
    /**
    typedef NS_ENUM(NSInteger, UITableViewRowActionStyle) {
        UITableViewRowActionStyleDefault = 0,
        UITableViewRowActionStyleDestructive =                 UITableViewRowActionStyleDefault,
        UITableViewRowActionStyleNormal
    } NS_ENUM_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
    /
    // 看得出来这三个枚举很扯淡...一个默认,一个一般,一个等于默认...
    // 回调方法里写点击事件
    UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleNormal) title:@"乐呵拉赫" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        NSLog(@"来给大爷笑一个");
    }];
    
    UITableViewRowAction *rowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"乐呵你妹" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        NSLog(@"doubi");
    }];
    
    UITableViewRowAction *rowAction3 = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleDefault) title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        NSLog(@"删了");
    }];
    UITableViewRowAction *rowAction4 = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleDestructive) title:@"111" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        NSLog(@"222");
    }];
    rowAction.backgroundColor = [UIColor redColor];
    rowAction2.backgroundColor = [UIColor greenColor];
    NSArray *array = @[rowAction,rowAction3,rowAction2,rowAction4];
    return array;
}

这个方法里面,左拉框会根据你内部的文字大小自适应宽度,高度与cell等宽
UITableViewRowAction一共有三个可变属性,文字,背景色和毛玻璃效果

@property (nonatomic, readonly) UITableViewRowActionStyle style;
@property (nonatomic, copy, nullable) NSString *title;
@property (nonatomic, copy, nullable) UIColor *backgroundColor; // default background color is dependent on style
@property (nonatomic, copy, nullable) UIVisualEffect* backgroundEffect;

好了,苹果每次更新基本都能提供一些最近流行的,比较好用的方法属性的,记录下来吧

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 2017.02.22 可以练习,每当这个时候,脑袋就犯困,我这脑袋真是神奇呀,一说让你做事情,你就犯困,你可不要太...
    Carden阅读 1,388评论 0 1
  • 文/老晨 温泉在云端目录 [小说]温泉在云端(连载四十二) 第二十五章 “放心,说的全部是你的好话。”Jennif...
    老_晨阅读 433评论 0 1
  • 小小一张图 幼稚又天真 浓浓尊师意 尽在不言中 纯洁心灵白如纸 岂任随意描画 今生既从教 倾心育桃李 匆匆三十载 ...
    梅子青青_d4b3阅读 208评论 0 0
  • Lynn 人们总是相信工作效率、能力、可靠性以及勤奋工作是让他们有机会提升的重要条件,但并不是具备这些条件你就能在...
    羽宙儿阅读 638评论 0 0