Forum Archive

TableView Button Color

Maxmad68

Hello,
I would like to know how can I change the color of the "Delete" button which appears when we swipe a row in a ui.TableView ?
The purpose is to change the color, the title and the action of that button for some rows
Is it possible with objc_util ?
Thanks

(Sorry for my bad english, I'm a french 16 years old boy)

zrzka

Hi,

here's the example how to use UITableViewRowAction for this purpose.

#!python3

import ui
from objc_util import *

#
# UITableViewDelegate
#

def handler(_cmd, action, index_path):
    print('Trash it!')

block_handler = ObjCBlock(handler, restype=None, argtypes=[c_void_p, c_void_p, c_void_p])       

def tableView_editActionsForRowAtIndexPath_(self, cmd, table_view, index_path):
    yellow = ObjCClass('UIColor').yellowColor()

    action = ObjCClass('UITableViewRowAction').rowActionWithStyle_title_handler_(0, ns('Trash it!'), block_handler)
    action.setBackgroundColor(yellow)

    return ns([action]).ptr


def make_table_view_delegate():
    methods = [tableView_editActionsForRowAtIndexPath_]
    protocols = ['UITableViewDelegate']
    delegate = create_objc_class('CustomTableViewDelegate', methods=methods, protocols=protocols)
    return delegate.alloc().init()

#
# UITableView
#

table_view = ui.TableView(name='Custom Action', frame=(0, 0, 300, 480))
table_view.data_source = ui.ListDataSource(['Hallo', 'Hi', 'Ciao'])

table_view_objc = ObjCInstance(table_view)
table_view_objc.setDelegate(make_table_view_delegate())

table_view.present('sheet')