@frankL still better
import ui
from objc_util import *
v = ui.View()
v.frame = (0,0,400,200)
v.background_color = 'white'
sc = ui.SegmentedControl()
items = ['abcd','abcd','abcd','abcd']
d = (v.width-2*10)/len(items)
sc.segments = items
sc.frame = (10,10,d*len(items),d)
o = ObjCInstance(sc).segmentedControl()
for i in range(len(items)):
with ui.ImageContext(d,d) as ctx:
#path = ui.Path.rounded_rect(0,0,d,d,5)
#ui.set_color('lightgray')
#path.fill()
s = 14 + i*3
font = ['Menlo', 'Bradley Hand', 'Courier New', 'Arial Rounded MT Bold'][i]
color = ['red', 'blue', 'green', 'brown'][i]
ui.draw_string(items[i], rect=(0,(d-s)/2,d,s), font=(font, s), color=color, alignment=ui.ALIGN_CENTER)
ui_image = ctx.get_image().with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
o.setImage_forSegment_(ui_image.objc_instance,i)
v.add_subview(sc)
v.present('sheet')
