当我使用tableView:editActionsForRowAt:在 iOS 应用程序中提供一些有用的功能时。
func tableView(_ tableView: UITableView,
editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
print(#function)
.... useful code .....
}
我已经到了与上面类似的其他一些 API 的点,但是在向右滑动时触发,而不是像tableView:editActionsForRowAt:这样的向左滑动会很有用。像这样说:
func tableView(_ tableView: UITableView,
editMoreActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
print(#function)
.... useful code .....
}
浏览网络我发现了 UITableViewDelegate 协议的这两种方法:
tableView:leadingSwipeActionsConfigurationForRowAt
tableView:trailingSwipeActionsConfigurationForRowAt
经过一些基本的实验,我想我可以得到我想要的,使用tableView:leadingSwipeActionsConfigurationForRowAt,因此在单元格的右侧滑动时为用户提供更多功能。但似乎这种方法并没有提供太多的自由。例如,这里是我的代码(非常受我在互联网上找到的一些示例的启发):
func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt
indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let modifyAction = UIContextualAction(style: .normal, title: nil, handler: {
(ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
modifyAction.image = UIImage(named: "MyNiceIcon")!.withColor(color: .black)
modifyAction.backgroundColor = .clear
return UISwipeActionsConfiguration(actions: [modifyAction])
}
即使存在这些行,这里:
modifyAction.image = UIImage(named: "MyNiceIcon")!.withColor(color: .black)
modifyAction.backgroundColor = .clear
MyNiceIcon 保持白色,按钮的背景为灰色。
我错过了什么吗?还是只能使用白色的图像颜色?而且背景颜色永远不透明?