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.


    Just for fun: ui.ButtonItem multi-lines

    Pythonista
    3
    5
    2006
    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.
    • cvp
      cvp last edited by

      import ui
      from objc_util import *
      
      v = ui.View()
      
      def b_action(sender):
      	print(sender)
      
      b = ui.ButtonItem()
      b.action = b_action
      
      # set a ButtonItem custom view as an ui.Button where we can, via ObjectiveC
      # put its title (label text) as multilines
      vv = ui.Button()
      vv.title = 'aaa\nbbb'
      vv.tint_color = 'green'
      vv.action = b_action
      vv.frame = (0,0,100,32)
      vvo = ObjCInstance(vv)
      for sv in vvo.subviews(): 
      	if hasattr(sv,'titleLabel'):
      		tl = sv.titleLabel()
      		tl.numberOfLines = 0
      		tl.adjustsFontSizeToFitWidth = True # auto resize font to fit
      		break
      ObjCInstance(b).customView = vvo
      
      v.right_button_items = (b,)
      v.present() 
      

      mikael 1 Reply Last reply Reply Quote 0
      • stephen
        stephen last edited by

        this is wonderfull! this should be implemented in the ui module as standard functionality! great job @cvp as usual

        1 Reply Last reply Reply Quote 0
        • mikael
          mikael @cvp last edited by

          @cvp, thanks for the multiline but also for making me aware of adjustsFontSizeToFitWidth. I am a bit cunfused, though, as the docs say it only applies to single-line labels.

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @mikael last edited by cvp

            @mikael you're right, perhaps is adjustsFontSizeToFitWidth not needed... The doc says
            "only intended for use with a single-line label". Not very clear.
            Some tests show it does not work.
            Thanks for the correction, thus let us keep only the multi-line aspect 🙄

            1 Reply Last reply Reply Quote 0
            • stephen
              stephen last edited by

              @cvp @mikael possibly documented because Developer may not of done extensive testing with larger numbers of lines? or even testing difernt text wraping? just to cover the posibility of bugs between releases..?

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors