如何在动作的中心设置图标?
我正在使用此代码添加3个操作colurCode
Done/Undo
& Delete
所有这些在细胞上滑动时几乎占据了细胞的所有空间。我想添加自定义图标而不是文本,但是当我添加它时它不显示在我的滑块中,也许它不是在动作中居中,我该怎么做? :
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 :(得分:1)
您可以像 static Color VectorInterpolate(float mix, Color c0, Color c1)
{
float alt = 1.0f - mix;
double x0 = c0.R;
double y0 = c0.G;
double z0 = c0.B;
double x1 = c1.R;
double y1 = c1.G;
double z1 = c1.B;
double mag0 = Math.Sqrt(x0 * x0 + y0 * y0 + z0 * z0);
double mag1 = Math.Sqrt(x1 * x1 + y1 * y1 + z1 * z1);
double x = mix * x0 + alt * x1;
double y = mix * y0 + alt * y1;
double z = mix * z0 + alt * z1;
double mag = mix * mag0 + alt * mag1;
double scale = mag / Math.Sqrt(x * x + y * y + z * z);
return Color.FromRgb(Clamp(x * scale), Clamp(y * scale), Clamp(z * scale));
}
static byte Clamp(double value)
{
var x = (int)Math.Round(value);
if (x > 255) return 255;
if (x < 0) return 0;
return (byte) x;
}
row action title
添加一些空白区域
" Delete "