2017-09-28 3 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.image = UIImage(named: "DeleteIcon.png") 

そして、それが動作するはずです:

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

へ。

0

IOS11以下では、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 
    } 
関連する問題