@mikael said:
@DavinE, the more recent and better version of UI constraints is here.
But even without going there, as @JonB said, you can get quite a lot done with just a GridView, which is now bundled with uiutils (pip install pythonista-uiutils).
The following short example demostrates 3 things that may be of interest if you are trying to create flexible UIs targeting both iPads and iPhones, and want your UI to survive someone rotating the device:
- Define an area to fill a percentage of the screen (plain ui flex).
- Avoid the controls at the edges of phone displays by using the SafeAreaView.
- Use GridView to layout views (buttons) automatically.
```
import ui
from uiutils.safearea import SafeAreaView
from uiutils.gridview import GridView
def create_button_slot(title):
slot = ui.View(
background_color='darkgrey',
)
btn = ui.Button(
title=title,
background_color='white',
tint_color='black',
flex='TWB'
)
btn.size_to_fit()
btn.height = btn.height + 16
btn.width = slot.width
btn.corner_radius = btn.height/2
btn.center = slot.bounds.center()
slot.add_subview(btn)
return slot
root = SafeAreaView(
background_color='lightgrey'
)
button_area_percentage = 23
button_area = GridView(
pack=GridView.FILL,
background_color='grey',
frame=(0, 100-button_area_percentage, 100, button_area_percentage),
flex='TWH',
)
root.add_subview(button_area)
for i in range(6):
button_area.add_subview(create_button_slot(f'Button {i+1}'))
root.present("fullscreen", animated=False)
```
i have a Problem with the UI constraints..
i Installed anchors but i get the message that the Module named 'anchor' is not found...
EDIT: i found the solution:
observer.py
this code is wrong:
import anchor.objc_plus as objc_plus
this is right:
import anchors.objc_plus as objc_plus