2017-09-28 24 views
0

我使用下面的代码,试图让这一下:在编辑模式下添加一个图像的UITableViewCell未对准正确

enter image description here

而是它看起来像:

enter image description here

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
    let deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Delete") { action, indexPath in 

    } 
    deleteRowAction.backgroundColor = UIColor.red 
    deleteRowAction.backgroundColor = UIColor(patternImage: UIImage(named: "DeleteIcon.png")!) 
    return [deleteRowAction] 
    } 

我在做什么错?

回答

0

只是改变:

deleteRowAction.backgroundColor = UIColor(patternImage: UIImage(named: "DeleteIcon.png")!) 

到:

deleteRowAction.image = UIImage(named: "DeleteIcon.png") 

,它应该工作。

0

在IOS 11以下,editActionsForRowAt方法在背景中显示模式图像,如果图像很小,则在图像大小的情况下重复图案图像。 这就是为什么要使用第三方实现这个SwipeCellKit

如果你实现这个在IOS 11然后使用这个功能的UITableViewDelegate,它完美地工作,例如:

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

     let deleteAction = UIContextualAction(style: .normal, title: "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in 
      // Call edit action 

      // Reset state 
      success(true) 
     }) 
     deleteAction.image = #imageLiteral(resourceName: "Delete") 
     deleteAction.backgroundColor = .red 
     let value = UISwipeActionsConfiguration(actions: [deleteAction]) 
     value.performsFirstActionWithFullSwipe = true 
     return value 
    } 
相关问题