2017-03-25 3 views
0

アクションの中心にアイコンを設定するにはどうすればよいですか? 私は3つのアクションを追加するこのコードを使用していますcolurCodeDone/Undo & Deleteこれらのすべては、セル上でスワイプすると、ほとんどすべてのセルのスペースがかかります。テキストの代わりにカスタムアイコンを追加したいのですが、それを追加するとスライダーに表示されません。おそらくアクションの中心にないので、どうすればいいですか? :editActionsForRowAtアクションにアイコンを合わせるには

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 


    let delete = UITableViewRowAction(style: .normal, title: "Delete") { (action, indexPath) in 
     let task = self.tasks[indexPath.row] 
     let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext 
     self.tasks.remove(at: indexPath.row) 
     context.delete(task) 
     (UIApplication.shared.delegate as! AppDelegate).saveContext() 
     tableView.deleteRows(at: [indexPath], with: .automatic) 
     //tableView.reloadData() 

    } 

    let colorCode = UITableViewRowAction(style: .normal, title: "Color") { (action, indexPath) in 


     let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popOver")as! popUpViewController 
     self.addChildViewController(popOverVC) 
     popOverVC.view.frame = self.view.frame 
     self.view.addSubview(popOverVC.view) 
     popOverVC.didMove(toParentViewController: self) 
     tableView.setEditing(false, animated: true) 
    } 



    let cell=tableView.cellForRow(at: indexPath) as! CustomCell 

    if cell.checkTest.on{ 
     let undone = UITableViewRowAction(style: .normal, title: "Undo") { (action, indexPath) in 
      let task = self.tasks[indexPath.row] 
      task.checkDone = "off" 
      (UIApplication.shared.delegate as! AppDelegate).saveContext() 
      // Update Cell 
      cell.stopanimate() 
      tableView.setEditing(false, animated: true) 
     } 
     undone.backgroundColor = UIColor.lightGray 
     delete.backgroundColor = UIColor(patternImage: UIImage(named: "red dot")!) 
     return [delete, undone, colorCode] 

    } 
    else{ 
     let done = UITableViewRowAction(style: .normal, title: "Done") { (action, indexPath) in 
      let task = self.tasks[indexPath.row] 
      task.checkDone = "on" 
      (UIApplication.shared.delegate as! AppDelegate).saveContext() 

      let cell=tableView.cellForRow(at: indexPath) as! CustomCell 
      cell.makeanimate()     
      tableView.setEditing(false, animated: true) 
     } 
     done.backgroundColor = UIColor.lightGray 
     delete.backgroundColor = UIColor(patternImage: UIImage(named: "tick1")!) 
     return [delete, done, colorCode] 


    } 


} 
+0

他のタイトルは何のようなあなたのrow action titleにいくつかの空白を追加することができますか? – Joe

+0

@Joe私の質問を編集しました:) –

+0

タイトルの代わりにアイコンを使うことを検討してください。 – Joe

答えて

0

あなたは、単にこの" Delete "

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 

let delete = UITableViewRowAction(style: .normal, title: "  Delete  ") { (action, indexPath) in 

} 
return [delete] 
} 
+0

私の行には2つの他のアクションもあります。そのため、すべてが幅があります。それぞれのカスタム幅を設定することはできますか? –

関連する問題