i update tableview_rowheight in the repo above to include an example changing the headerview background.
in short
@on_main_thread
def tableView_willDisplayHeaderView_forSection_(_self,_sel,tv, v,section):
tv_o=objc_util.ObjCInstance(_self)
pyo=tv_o.pyObject(restype=c_void_p,argtypes=[])
tv_py=ctypes.cast(pyo.value,ctypes.py_object).value
if tv_py.delegate and hasattr(tv_py.delegate,'will_display_header'):
tv_py.delegate.will_display_header(v,section)
this checks for tv.delegate.will_display_header(v,section), and calls it with the headerview.
Setting up the swizzle needs to only happen once -- could do it in main of an imported module for instance. multiple times wont hurt, in theory.
def setup_tableview_swizzle(override=False):
t=ui.TableView()
t_o=ObjCInstance(t)
encoding=b'v@:@@i'
swizzle.swizzle(ObjCClass(t_o._get_objc_classname()),
('tableView:willDisplayHeaderView:forSection:'),
tableView_willDisplayHeaderView_forSection_,encoding)
to change the color you would then define said delegate method, for example
def will_display_header(v,section):
ObjCInstance(v).contentView().backgroundColor=UIColor.redColor()