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.
-
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?
-
-
@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?
-
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 said:
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.fontdef 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.
-
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 -
@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.
-
@satsuki.kojima did you read this ?
-
@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.