iOS Question CustomView with integrated custom font

Filippo

Expert
Licensed User
Longtime User
Hi,

I would like to integrate a custom font into a CustomView (B4xlib-library) without having to use the “#AppFont:” attribute in the main module.
The custom font is available in the B4xlib-library under “..\File\Special”.
Is this possible? If so, how?

Thank you for the answer
Filippo
 

Filippo

Expert
Licensed User
Longtime User
The library name should be Files\Special. I think that it will be copied correctly. Check it.
Yes, that is correct. The library is copied twice, once under “..\File” for Android and once under “..\File\Special” for iOS.

But you will need to add the #AppFont attribute.
I would find it better if this attribute were only added in the library, that would avoid errors.

It would be great if you could make it possible. ;-)
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
I have no programming experience with B4I, but in B4J and B4A I load a font via XUI program code from the assets file folder. See also [B4X] MaterialIcons Web Font Chooser
Possible B4X solution:
' Declare a variable for the custom font
Private CustomFont As B4XFont

' Initialize the font from the assets directory
CustomFont = xui.CreateFont(File.OpenInput(File.DirAssets, "CustomFont.ttf"), 16)

' Apply the font to a label
Label1.Font = CustomFont
 
Upvote 0

b4x-de

Active Member
Licensed User
Longtime User
Just to add one small but important detail after testing this in B4i release mode:

The font file can indeed be included in the .b4xlib under:

B4X:
Files\Special

and the consuming B4i app still needs to add the #AppFont attribute. What was not obvious to me at first: the filename used in #AppFont must be lowercase.

I initially used:

B4X:
#AppFont: B4X_FontAwesome.otf
#AppFont: B4X_MaterialIcons.ttf

The files were present with lower case letters in the app bundle, but iOS did not register them. This caused the a runtime error when calling xui.CreateFontAwesome().

The working version was:

B4X:
#AppFont: b4x_fontawesome.otf
#AppFont: b4x_materialicons.ttf

So the rule seems to be:

  • Put the font files in the .b4xlib under Files\Special.
  • Add #AppFont in the consuming B4i project.
  • Make sure that the #AppFont filename exactly matches the copied bundle filename, that is lowercase.

This is easy to miss on Windows, where filename casing usually does not matter during development.
 
Upvote 0
Top