Forum Archive

How to use [ui Var].frame properly

NewbieCoder

Im a noob and im not really sure how to use the ui.frame command correctly to assign where a button will be located. Here is a case to show a bit further into my question...

import ui

v = ui.View()
v.frame = (0,0,400,400)
v.name = 'test'

b = ui.Button()
b.title = 'My Title'
b.background_color = 'white'
b.border_color = 'blue'
b.border_width = 1
b.corner_radius = 5
b.frame = (10,10,100,32)
a = ''
def tap(sender):
    a = sender.title
    print(a)    
b.action = tap
v.add_subview(b)
v.present('sheet')
ccc
def tap(sender):
    new_frame = (sender.frame[0] + 10, sender.frame[1] + 10, 
                 sender.frame[2] - 1, sender.frame[3] - 1)
    sender.frame = new_frame
mikael

@NewbieCoder, your code seems to work, so what is the challenge you have?

Some key points about frame are that:

  • it refers to coordinates within the parent view
  • bounds can be used to access parent’s internal dimensions
  • root views only become full screen after being presented
  • flex can be used to make the frame change as the parent view’s size changes