omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How to use [ui Var].frame properly

    Pythonista
    3
    3
    1335
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NewbieCoder
      NewbieCoder last edited by ccc

      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')
      
      mikael 1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by 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
        
        1 Reply Last reply Reply Quote 0
        • mikael
          mikael @NewbieCoder last edited by

          @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
          1 Reply Last reply Reply Quote 2
          • First post
            Last post
          Powered by NodeBB Forums | Contributors