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.


    Can I add custom fonts in font picker.

    Pythonista
    custom font uifontpickervie
    4
    9
    2732
    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.
    • satsuki.kojima
      satsuki.kojima last edited by

      I want to show some custom fonts in a font picker. I’m currently using ‘UIFontPickerViewController’ for listing fonts and I have installed some custom fonts in iOS, but I don’t know how or if I can add those fonts in the font picker. Can I and how?

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

        https://forum.omz-software.com/topic/6526/font-listing-selection

        1 Reply Last reply Reply Quote 0
        • mikael
          mikael @satsuki.kojima last edited by

          @satsuki.kojima, Apple docs state that:

          ”Use a UIFontPickerViewController to provide the user access to all the fonts on their device. Directly querying UIFont provides only system fonts, but the user may have additional fonts on their device. When the user selects one of these nonsystem fonts in the font picker, the system grants your app access to the font.”

          This seems like all fonts should be visible. Can you give some more details about what does not work?

          satsuki.kojima 1 Reply Last reply Reply Quote 0
          • satsuki.kojima
            satsuki.kojima @mikael last edited by ccc

            @mikael

            I have picked the part of my codes to show the picker. And I also have installed some custom fonts in iOS and they are seen in setting.

            ==============================================================
            import ui
            from objc_util import *
            
            def UIFontPickerViewController():
            	v = ui.View()
            	vc = ObjCInstance(v)
            	fontpicker = ObjCClass('UIFontPickerViewController').new().autorelease()
            	fontview = fontpicker.view()
            	v.frame = (0,0,512,960)
            	vc.addSubview_(fontview)
            	done_button = ui.ButtonItem(title='OK')
            	def tapped(sender):
            		sel = fontpicker.selectedFontDescriptor()
            		if sel != None:
            			v.font= str(sel.objectForKey_('NSFontFamilyAttribute'))
            		v.close()
            	done_button.action = tapped
            	v.right_button_items = [done_button]
            	v.font = None
            	v.present('sheet')
            	v.wait_modal()
            	return v.font
            
            def show_font_picker(sender):
            	
            	font = UIFontPickerViewController()
            	print(font)
            	if font != None:
            		label.text = font
            		label.font = (font, 18)		
            		
            		
            root = ui.View(bg_color='white')
            button = ui.Button(
            		frame=(100,100,150,60),
                title='Pick font',
                border_width=1,
                action=show_font_picker
            )
            label = ui.Label(
            		frame=(200,100,300,60),
            		tint_color='black',
            		border_width=1)
            		
            root.add_subview(button)
            root.add_subview(label)
            root.present('fullscreen')
            ============================================================
            
            satsuki.kojima mikael 2 Replies Last reply Reply Quote 0
            • satsuki.kojima
              satsuki.kojima @satsuki.kojima last edited by

              @satsuki.kojima said:

              @mikael

              I have picked the part of my codes to show the picker. And I also have installed some custom fonts in iOS and they are seen in setting.

              ==============================================================
              import ui
              from objc_util import *

              def UIFontPickerViewController():
              v = ui.View()
              vc = ObjCInstance(v)
              fontpicker = ObjCClass('UIFontPickerViewController').new().autorelease()
              fontview = fontpicker.view()
              v.frame = (0,0,512,960)
              vc.addSubview_(fontview)
              done_button = ui.ButtonItem(title='OK')
              def tapped(sender):
              sel = fontpicker.selectedFontDescriptor()
              if sel != None:
              v.font= str(sel.objectForKey_('NSFontFamilyAttribute'))
              v.close()
              done_button.action = tapped
              v.right_button_items = [done_button]
              v.font = None
              v.present('sheet')
              v.wait_modal()
              return v.font

              def show_font_picker(sender):

              font = UIFontPickerViewController()
              print(font)
              if font != None:
              label.text = font
              label.font = (font, 18)

              root = ui.View(bg_color='white')
              button = ui.Button(
              frame=(100,100,150,60),
              title='Pick font',
              border_width=1,
              action=show_font_picker
              )
              label = ui.Label(
              frame=(200,100,300,60),
              tint_color='black',
              border_width=1)

              root.add_subview(button)
              root.add_subview(label)
              root.present('fullscreen')

              Well, tab spaces were cut from the above codes when embedded to here. If you could try the above codes in your device, need to fix the tabs.

              cvp 1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by ccc

                Code blocks in this forum work like
                https://docs.github.com/en/free-pro-team@latest/github/writing-on-github/creating-and-highlighting-code-blocks

                1 Reply Last reply Reply Quote 0
                • mikael
                  mikael @satsuki.kojima last edited by

                  @satsuki.kojima, FYI, what I did:

                  • Installed a custom font with iFont
                  • Confirmed in Pages that the font was visible and usable
                  • Tried your code. Font was not visible.
                  • Tried a picker wrapper I had around. Font was not visible.
                  • Set the picker to also show font faces where available. Font was not visible.
                  1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @satsuki.kojima last edited by

                    @satsuki.kojima did you read this ?

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

                      @cvp, all I see them saying is ”use UIFontPickerViewController”, which we are using here. I suspect there is something missing in Pythonista plist or similar.

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