I'm trying to customize the UITableViewRowAction buttons, so instead of the default button, I use an image.
My problem is that the cell height is dynamic, so if the cell height was so big, the image in the UITableViewRowAction repeats! Like this:

so how can I keep the image always in the center, regardless of the height of the cell?
my code is:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let deleteAction: UITableViewRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: " ", handler: {(tableViewRowAction:UITableViewRowAction, index:NSIndexPath) -> Void in
self.deleteFavouriteLocationFromList(indexPath.row)
})
let image:UIImage = UIImage(named: "delete_icon_cell")!
image.imageWithRenderingMode(UIImageRenderingMode.Automatic)
let size = CGSizeApplyAffineTransform(image.size, CGAffineTransformMakeScale(0.29, 0.3))
let hasAlpha = false
let scale: CGFloat = 0.0
UIGraphicsBeginImageContextWithOptions(size, !hasAlpha, scale)
image.drawInRect(CGRect(origin: CGPointZero, size: size))
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
deleteAction.backgroundColor = UIColor(patternImage: scaledImage)
let editAction: UITableViewRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: " ", handler: {(tableViewRowAction:UITableViewRowAction, index:NSIndexPath) -> Void in
self.presentEditFavouriteLocationNamePopUp(indexPath.row)
})
let editImage:UIImage = UIImage(named: "edit_icon_cell")!
UIGraphicsBeginImageContextWithOptions(size, !hasAlpha, scale)
editImage.drawInRect(CGRect(origin: CGPointZero, size: size))
let editScaledImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
editAction.backgroundColor = UIColor(patternImage: editScaledImage)
return [deleteAction,editAction]
}
thank.
source
share