@ramvee This example is great!
One of the things that I found when I first started using the ui module was that when I did not use .pyui files then my code got long and repetitive. Often I want all my ui elements to share a common look and feel (bg_color, border_color, border_width, etc.) and I only need to set a few unique values like name and frame. To reduce this code bloat, I recommend creating a make_label() function that puts all the common stuff inside and accepts as parameters from the outside the unique stuff...
# Learning Alignment Options In UI
# Pythonista
# Flex LRTBWH
import ui
def make_label(name, frame):
return ui.Label(
alignment=1,
bg_color='yellow',
border_color='black',
border_width=1,
frame=frame,
flex=name,
name=name,
text=name)
w, h = ui.get_screen_size()
h -= 64
bh = bw = 80 # label height and button width
mg = 10 # margin
view = ui.View(name='Flex', bg_color='lightyellow', frame=(0, 0, w, h))
view.add_subview(make_label(name='RB', frame=(mg, mg, bw, bh)))
view.add_subview(make_label(name='LB', frame=(w - (bw + mg), mg, bw, bh)))
view.add_subview(make_label(name='RT', frame=(mg, h - (bh + mg), bw, bh)))
view.add_subview(make_label(name='LT',
frame=(w - (bw + mg), h - (bh + mg), bw, bh)))
view.add_subview(make_label(name='LRTB',
frame=((w - bw) * .5, (h - bh) * .5, bw, bh)))
view.present()