我正在尝试为我的表格视图中的滑动操作添加自定义UIImage
。我的图像存在(我可以在定义我的变量时看到它们)但是在运行我的应用程序时,我只有一个白色圆圈而不是橙色标记。看起来图像的内容(但不是形状)缺失。
@available(iOS 11, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let molecule = moleculesWithSections[indexPath.section][indexPath.row]
var favouriteStatus: NSNumber!
var image: UIImage!
if molecule.isFavorite == true {
favouriteStatus = false
image = #imageLiteral(resourceName: "unflagged")
}
else {
favouriteStatus = true
image = #imageLiteral(resourceName: "flagged")
}
let flagAction = UIContextualAction(style: .normal, title: "") { (action, view, handler) in
molecule.isFavorite = favouriteStatus
tableView.setEditing(false, animated: true)
MoleculeStore.shared().saveChanges()
//self.reloadSections()
print(handler(true))
}
flagAction.image = image
let configuration = UISwipeActionsConfiguration(actions: [flagAction])
configuration.performsFirstActionWithFullSwipe = false
return configuration
}
有人会知道发生了什么吗?非常感谢
答案 0 :(得分:-1)
您可能正在使用模板渲染。使用原文:
image = #imageLiteral(resourceName: "unflagged").withRenderingMode(.alwaysOriginal)
和
image = #imageLiteral(resourceName: "flagged").withRenderingMode(.alwaysOriginal)