是什么?
-
Deprecated
- 不推荐使用 @interface UITableViewRowAction : NSObject <NSCopying>
- 用户在表格"行"中水平滑动时,要显示的单个操作.
有什么用?
- 为表行,定义单个自定义操作. 如下图所示的,自定义"关注"按钮.
怎么使用?
- 创建并返回一个新的表格视图行操作对象.
+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style
title:(NSString *)title
handler:(void (^)(UITableViewRowAction *action, NSIndexPath *indexPath))handler;
-
style:
应用于按钮样式的特征.-
UITableViewRowActionStyleDestructive
红色背景 -
UITableViewRowActionStyleNormal
灰色背景
-
typedef NS_ENUM(NSInteger, UITableViewRowActionStyle) {
UITableViewRowActionStyleDefault = 0, // 默认样式,应用于按钮.
UITableViewRowActionStyleDestructive = UITableViewRowActionStyleDefault, //
UITableViewRowActionStyleNormal
}
-
title:
按钮中显示的字符串. -
handler:
代理. 用户点击操作按钮时,做什么的代码块.-
action:
事件 -
indexPath:
用户操作的表格行.
-
有什么特点?
backgroundColor :
设置操作按钮背景的颜色/背景颜色图片
backgroundEffect :
设置操作按钮背景的视觉效果
示例?
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction *signAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"关注" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
NSLog(@"-----------=关注");
}];
....
//操作按钮,颜色背景图片.
deleteAction.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"newWine"]];
signAction.backgroundColor = [UIColor grayColor];
return @[deleteAction,signAction];
}
也可以看看
UIContextualAction - 用户滑动表格行后,执行操作的事件
UISwipeActionsConfiguration - 表格行滑动后的操作配置
来自于哪里?
- iOS-MJ-UI基础-大神班/day-10/左滑出现多个按钮
网友评论