首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 12 UIContextualAction图像不推断图像颜色

iOS 12 UIContextualAction图像不推断图像颜色
EN

Stack Overflow用户
提问于 2021-02-20 09:28:15
回答 1查看 353关注 0票数 2

在iOS 12中,UIContextualAction并没有推断出图片的颜色。虽然它适用于iOS 13和更多版本。我尝试过图标的所有呈现模式,但仍然不起作用。

代码语言:javascript
复制
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let deleteAction = UIContextualAction(style: .normal, title: "") { _, _, complete in
    }
    let editAction = UIContextualAction(style: .normal, title: "") { _, _, complete in
    }
    
    deleteAction.image = UIImage(named: "trashcan")
    editAction.image = UIImage(named: "cellEdit")
    let configuration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
    return configuration
}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-20 09:34:13

你可以试试这个

代码语言:javascript
复制
class ImageWithoutRender: UIImage {
    override func withRenderingMode(_ renderingMode: UIImage.RenderingMode) -> UIImage {
        return self
    }
}

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    
    let deleteAction = UIContextualAction(style: .normal, title: "") { _, _, complete in
    }
    let editAction = UIContextualAction(style: .normal, title: "") { _, _, complete in
    }
    
    
    if let cgImageTrashcan =  UIImage(named: "trashcan")?.cgImage {
        deleteAction.image = ImageWithoutRender(cgImage: cgImageTrashcan, scale: UIScreen.main.nativeScale, orientation: .up)
    }
    
    if let cgImageCellEdit =  UIImage(named: "cellEdit")?.cgImage {
        editAction.image = ImageWithoutRender(cgImage: cgImageCellEdit, scale: UIScreen.main.nativeScale, orientation: .up)
    }
    
    let configuration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
    return configuration
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66289965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档