Hey everyone,
I am currently having some problems with the ui-module in Pythonista.
The following code is a representation of the situation I am dealing with in my program:
import ui
def sw1_changed(sender):
if sender.value == True:
# switch has been turned on
v.height = 400
else:
# switch has been turned off
v.height = 200
v = ui.View()
v.name = "View"
v.width = 200
v.height = 200
v.bg_color = 1.0
v.border_width = 3
v.border_color = (1.0, 0.0, 0.0)
sw1 = ui.Switch()
sw1.name = "Switch"
sw1.action = sw1_changed
sw1.center = (v.width/2, v.height/2)
v.add_subview(sw1)
v.present('sheet')
Briefly explained:
I created a ui.View object that contains a ui.Switch object as a subview. When the switch is pressed the size of the its parent view is supposed to change. If the switch is turned on, it‘s height should increase from 400 to 200 and when it‘s turned off, it should turn back to it‘s original height of 200.
My problem:
(Running the code yourself could be helpful to understand what I mean.)
The resizing behaviour of the View does not work out as I want it to. The program does change the View‘s height in some way which is shown by the red border surrounding View. The bottom of the border disappears when the switch is turned on which (I think) means that it expands it‘s space where subviews could be placed onto. However the added space is not visible on the screen.
My question is: How can I get the View to change it‘s height so that it covers a bigger part on the screen?
I‘ve already tried out some stuff with the View.bounds, View.frame and View.center as well as the type argument of the View.present method but none of it fixed my problem.
I would be really happy if someone could help me out with my problem. Thanks for every answer in advance. 😁