UITableViewRowAction картинка вместо текста

swift

#1

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
            
        }
    }
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let delete = TableViewRowAction(style: UITableViewRowActionStyle.Default, title: "         ") { action, indexPath in }
    delete.image = UIImage(named: "trashImg")
        
    let sharing = TableViewRowAction(style: UITableViewRowActionStyle.Default, title: "         ") { action, indexPath in }
    sharing.backgroundColor = UIColor.lightGrayColor()
    sharing.image = UIImage(named: "sharingImg")
        
    return [delete, sharing]
}

Скачать


Добавить Image row action
#2

как же долго я искал этот материал!спасибо вам и создателям этого ресурса!


#3

Спасибо большое!) Очень полезный код!


#4

Спасибо большое!:heart: