2015-11-26 12 views
11

Ho un UITableView e ho aggiunto azioni di modifica ad esso. Ora voglio aggiungere immagine sopra l'etichetta pulsanti di eliminazione, come:Come aggiungere un'immagine sul pulsante di cancellazione di UITableView?

enter image description here

Questo è il mio codice:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 

    let blockAction = UITableViewRowAction(style: .Normal, title: "Block") { (rowAction:UITableViewRowAction, indexPath:NSIndexPath) -> Void in 
     //TODO: Delete the row at indexPath here 
    } 
    blockAction.backgroundColor = UIColor.redColor() 

    return [blockAction] 
} 

Come posso aggiungere un'immagine sul mio tasto Delete?

+0

@rmaddy ma come altri sviluppatori fare che? –

+0

Forse stanno utilizzando una classe di celle di visualizzazione tabella personalizzata di terze parti e non utilizzano l'API standard fornita da 'UITableViewDelegate'. – rmaddy

+1

fai riferimento a queste domande, troverai la tua risposta: http://stackoverflow.com/questions/20290766/cambia-il-colore-del-funzionalità-del-color-delete-bottiglia-in-adeguataviewcell-quando- swap ---------------- http://stackoverflow.com/questions/29335104/how-add-custom-image-to-uitableview-cell-swipe-to -delete se si utilizza iOS8 + –

risposta

1

È possibile utilizzare un'immagine speciale sul colore di sfondo e utilizzare il simbolo '\ n' deluso per il testo

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 

    let blockAction = UITableViewRowAction(style: .normal, title: "\nBlock") { (rowAction:UITableViewRowAction, indexPath:IndexPath) -> Void in 
     //TODO: Delete the row at indexPath here 
    } 
    blockAction.backgroundColor = UIColor(patternImage: UIImage(named: "delete_background")!) 

    return [blockAction] 
} 
Problemi correlati