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 set the font size of segmented control titles

    Pythonista
    2
    4
    1033
    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.
    • frankL
      frankL last edited by

      how can I set the font size of segmented control titles? The font size it chooses is very small regardless of the number of tabs.
      I tried including a font definition in the ui.SementedControl like this:
      my_sc = ui.SementedControl(font=('Arial Rounded MT Bold',22))

      but regardless of the selection of the font size (vs 22) the displayed tab title size does not change.

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

        @frankL try this

        import ui
        from objc_util import *
        
        v = ui.SegmentedControl()
        v.background_color = 'white'
        v.frame =(0,0,300,50)
        v.segments = ['Seg1','Seg2','Seg3','Seg4']
        
        UIFont = ObjCClass('UIFont').fontWithName_size_('Arial Rounded MT Bold',22)
        attributes = {'NSFont': UIFont}
        vo= ObjCInstance(v).segmentedControl()
        vo.setTitleTextAttributes_forState_(attributes, 0)
        
        v.present('sheet')
        
        1 Reply Last reply Reply Quote 0
        • frankL
          frankL last edited by

          @cvp said:

          UIFont = ObjCClass('UIFont').fontWithName_size_('Arial Rounded MT Bold',22)
          attributes = {'NSFont': UIFont}
          vo= ObjCInstance(v).segmentedControl()
          vo.setTitleTextAttributes_forState_(attributes, 0)

          That's perfect, thank you.

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

            @frankL still better

            import ui
            from objc_util import *
            
            v = ui.View()
            v.frame = (0,0,400,200)
            v.background_color = 'white'
            
            sc = ui.SegmentedControl()
            items = ['abcd','abcd','abcd','abcd']
            d = (v.width-2*10)/len(items)
            sc.segments = items
            sc.frame = (10,10,d*len(items),d)
            
            o = ObjCInstance(sc).segmentedControl()
            for i in range(len(items)):
            	with ui.ImageContext(d,d) as ctx:
            		#path = ui.Path.rounded_rect(0,0,d,d,5)
            		#ui.set_color('lightgray')
            		#path.fill()
            		s = 14 + i*3
            		font = ['Menlo', 'Bradley Hand', 'Courier New', 'Arial Rounded MT Bold'][i]
            		color = ['red', 'blue', 'green', 'brown'][i]
            		ui.draw_string(items[i], rect=(0,(d-s)/2,d,s), font=(font, s), color=color, alignment=ui.ALIGN_CENTER)
            		ui_image = ctx.get_image().with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
            	o.setImage_forSegment_(ui_image.objc_instance,i)
            v.add_subview(sc)
            
            v.present('sheet')
            

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