您需要根據您的需求來改變插圖。
class TableViewRowAction: UITableViewRowAction
{
var image: UIImage?
func _setButton(button: UIButton) {
if let image = image, let titleLabel = button.titleLabel {
let labelString = NSString(string: titleLabel.text!)
let titleSize = labelString.sizeWithAttributes([NSFontAttributeName: titleLabel.font])
button.tintColor = UIColor.whiteColor()
button.setImage(image.imageWithRenderingMode(.AlwaysTemplate), forState: .Normal)
button.imageEdgeInsets.right = -titleSize.width
}
}
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let moreRowAction = TableViewRowAction(style: UITableViewRowActionStyle.Default, title: " ") { action, indexPath in
// Action Block of more button.
}
moreRowAction.image = UIImage(named: "edit_white")
moreRowAction.backgroundColor = UIColor(red: 252/255, green: 65/255, blue: 75/255, alpha: 1.0)
let deleteRowAction = TableViewRowAction(style: UITableViewRowActionStyle.Default, title: " ") { action, indexPath in
// Action Block of delete button.
}
deleteRowAction.backgroundColor = UIColor(red: 252/255, green: 65/255, blue: 75/255, alpha: 1.0)
deleteRowAction.image = UIImage(named: "delete_white")
return [deleteRowAction, moreRowAction]
}
我已經試過,但它只是使圖像成爲背景,而不是它出現。 –
這聽起來像你可能只需要創建一個自定義的UITableViewCell並將您自己的自定義按鈕的圖像和標題放在單元格右側。是否有一個原因,你必須使用editAction? – bhmahler