UITableViewRowAction image for title

后端 未结 8 1791
情歌与酒
情歌与酒 2020-12-02 15:44

I made a custom UITableViewRowAction. Now I\'d like to add an image instead of the text. I know that it\'s possible but don\'t know how to do it. Does someone of you knows

相关标签:
8条回答
  • 2020-12-02 16:21
    delActions.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"delete.png"]];
    
    0 讨论(0)
  • 2020-12-02 16:30
    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) -> [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]
    }
    
    0 讨论(0)
提交回复
热议问题