2015-11-26 12 views
11

Mam UITableView i dodałem do niego akcje edycji. Teraz chcę dodać zdjęcie powyżej etykiecie Delete, jak:Jak dodać obraz na przycisku kasowania UITableView?

enter image description here

To jest mój kod:

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] 
} 

Jak mogę dodać zdjęcie na moim przycisku Delete?

+0

@rmaddy ale jak inni deweloperzy zrobić? –

+0

Być może używają one niestandardowej klasy komórki widoku innej firmy i nie używają standardowego interfejsu API udostępnianego przez "UITableViewDelegate". – rmaddy

+1

Skorzystaj z tego pytania, znajdziesz odpowiedź: http://stackoverflow.com/questions/20290766/change-the-color-of-default-red-color-delete-button-in-uitableviewcell-when- przesuń ---------------- http://stackoverflow.com/questions/29335104/how-add-custom-image-to-uitableview-cell-swipe-to -delete jeśli korzystasz z systemu iOS8 + –

Odpowiedz

1

można użyć specjalnych obrazu na kolor tła i wykorzystać „\ n” symbol dla zawieść tekst

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] 
}