使用白色背景颜色和深灰色图标添加拖尾滑动操作配置

时间:2018-03-29 12:14:03

标签: ios swift uitableview uitableviewrowaction

我正在尝试使用UITableViewUIContextualAction添加跟踪滑动操作,但图标不可见,因为图标变为白色,背景也是白色,当我更改背景颜色时,它是可见的。请帮我用它的颜色设置图标。我尝试搜索色彩属性,但没有这样的属性。以下是我尝试的代码。

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

    let delete =  UIContextualAction(style: .normal, title: nil, handler: { (action,view,completionHandler ) in
        //    Delete the row after API
    })

    //Solution 1
    delete.image = UIImage(named: "deleteicon")

    // Solution 2
    delete.image = UIGraphicsImageRenderer(size:CGSize(width: 30, height: 30)).image { _ in
        UIImage(named:"deleteicon")?.draw(in: CGRect(x: 0, y: 0, width: 30, height: 30))
    }

    // Solution 3
    edit.backgroundColor = UIColor(patternImage: UIGraphicsImageRenderer(size:CGSize(width: 30, height: 30)).image { _ in UIImage(named:"favouriteinactiveicon")?.draw(in: CGRect(x: 0, y: 0, width: 30, height: 30))})

    let confrigation = UISwipeActionsConfiguration(actions: [delete])
    return confrigation
}

0 个答案:

没有答案