2015-11-26 12 views
11

Tôi có UITableView và tôi đã thêm hành động chỉnh sửa vào nó. Bây giờ tôi muốn thêm hình ảnh trên nhãn nút delete, như:Làm cách nào để thêm hình ảnh vào nút xóa UITableView?

enter image description here

Đây là mã của tôi:

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

Làm thế nào tôi có thể thêm hình ảnh vào nút của tôi Delete?

+0

@rmaddy nhưng làm thế nào các nhà phát triển khác làm điều đó? –

+0

Có lẽ họ đang sử dụng lớp ô xem bảng tùy chỉnh của bên thứ ba và không sử dụng API chuẩn được cung cấp bởi 'UITableViewDelegate'. – rmaddy

+1

tham khảo các câu hỏi này, bạn sẽ tìm thấy câu trả lời: http://stackoverflow.com/questions/20290766/change-the-color-of-default-red-color-delete-button-in-uitableviewcell-when- swip ---------------- http://stackoverflow.com/questions/29335104/how-add-custom-image-to-uitableview-cell-swipe-to -delete nếu bạn đang sử dụng iOS8 + –

Trả lời

1

Bạn có thể sử dụng hình ảnh đặc biệt về màu nền và sử dụng '\ n' biểu tượng cho thất vọng văn bản

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] 
} 
Các vấn đề liên quan