BGTableViewRowActionWithImage
注意:此项目一直有点像是某种特技 🤷🏼♂️,并且自 2018 年 3 月以来,由于 Apple 提供了 UIContextualAction
,作者不再维护该项目:https://developer.apple.com/documentation/uikit/uicontextualaction
对于 iOS 11 和更高版本,您必须使用以下替代方案!
这是 iOS 8.0+ UITableViewRowAction
的一个变种,用于支持图标和下面的文本。类似于 iOS 9 邮件应用程序和各种第三方应用程序。我们都秘密地希望 Apple 会在未来的 iOS 更新中通过本地公开 API 实现此功能。
此 iOS 8-10 实现并不是理想的选择,但它可以工作。在 iOS 11 及更高版本中,您必须使用 Apple 的内置 UIContextualAction
!在此库的默认配置下,它可能仍然适合您,但它不再受 iOS 11 及更高版本的支持。
Objective-C 使用方法
// Regular width
+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style
title:(NSString *)title
backgroundColor:(UIColor *)backgroundColor
image:(UIImage *)image
forCellHeight:(NSUInteger)cellHeight
handler:(void (^)(UITableViewRowAction *, NSIndexPath *))handler;
+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style
title:(NSString *)title
titleColor:(UIColor *)titleColor
backgroundColor:(UIColor *)backgroundColor
image:(UIImage *)image
forCellHeight:(NSUInteger)cellHeight
handler:(void (^)(UITableViewRowAction *, NSIndexPath *))handler;
// Optional fitted width (ideal when using 3 or more cells in smaller tables)
+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style
title:(NSString *)title
backgroundColor:(UIColor *)backgroundColor
image:(UIImage *)image
forCellHeight:(NSUInteger)cellHeight
andFittedWidth:(BOOL)isWidthFitted
handler:(void (^)(UITableViewRowAction *, NSIndexPath *))handler;
+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style
title:(NSString *)title
titleColor:(UIColor *)titleColor
backgroundColor:(UIColor *)backgroundColor
image:(UIImage *)image
forCellHeight:(NSUInteger)cellHeight
andFittedWidth:(BOOL)isWidthFitted
handler:(void (^)(UITableViewRowAction *, NSIndexPath *))handler;
根据您的需求,只需使用以下构造函数之一来配置每个行操作,手动设置行操作调用构造函数之后的 backgroundColor
属性可能会导致意外行为,因此应该避免。
Swift
对于 Swift,语法有一些轻微的变化
// In your imports:
import BGTableViewRowActionWithImage
// In your code:
BGTableViewRowActionWithImage.rowActionWithStyle(/* see above for parameters... */)
有关参数配置和其他重要注意事项,请参阅上面的“Objective-C 使用”部分。
示例
安装
BGTableViewRowActionWithImage
需要通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile
pod "BGTableViewRowActionWithImage"
作者
Ben Guild, [email protected]
许可证
BGTableViewRowActionWithImage
在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。