@samaklis almost that with
from objc_util import *
import ui
items = ['aaa','bbb']
v =ui.View()
v.background_color = 'black'
v.frame = (0,0,400,200)
s = ui.SegmentedControl()
s.corner_radius = 0
s.background_color = 'yellow'
s.segments = items
s.frame = (10,20,380,50)
v.add_subview(s)
t = ui.SegmentedControl()
t.corner_radius = 0
t.background_color = 'yellow'
t.segments = items
t.frame = (10,130,380,50)
def t_action(sender):
w = sender.width/len(items)
h = sender.height
idx = sender.selected_index
o = ObjCInstance(sender).segmentedControl()
#print(dir(o))
idx = o.selectedSegmentIndex()
for i in range(len(items)):
if i == idx:
with ui.ImageContext(w,h) as ctx:
path = ui.Path.rounded_rect(0,0,w,h,0)
ui.set_color('white')
path.fill()
s = 12
ui.draw_string(items[idx], rect=(0,(h-s)/2,w,s), font=('Menlo', s), color='black', alignment=ui.ALIGN_CENTER)
ui_image = ctx.get_image().with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
o.setImage_forSegment_(ui_image.objc_instance,idx)
else:
o.setTitle_forSegmentAtIndex_(items[i],i)
t.action = t_action
v.add_subview(t)
v.present('sheet')
