iOS Question [XUI] B4x Font

Emme Developer

Well-Known Member
Licensed User
Longtime User
Hi! Can anyone explain how can i right use b4x font?
I have a code module utils in which i load some fonts, i want to use same code on b4i.. thanks

B4X:
    Public const SansSemibold As Typeface = Typeface.LoadFromAssets("SourceSansPro-Semibold.otf")
    Public const SansLight As Typeface = Typeface.LoadFromAssets("SourceSansPro-Light.ttf")
    Public const SansBold As Typeface = Typeface.LoadFromAssets("SourceSansPro-Bold.otf")
    Public const SansBlack As Typeface = Typeface.LoadFromAssets("SourceSansPro-Black.ttf")
    Public const SansRegular As Typeface = Typeface.LoadFromAssets("SourceSansPro-Regular.otf")
 
D

Deleted member 103

Guest
Hi! Can anyone explain how can i right use b4x font?
I have a code module utils in which i load some fonts, i want to use same code on b4i.. thanks

B4X:
    Public const SansSemibold As Typeface = Typeface.LoadFromAssets("SourceSansPro-Semibold.otf")
    Public const SansLight As Typeface = Typeface.LoadFromAssets("SourceSansPro-Light.ttf")
    Public const SansBold As Typeface = Typeface.LoadFromAssets("SourceSansPro-Bold.otf")
    Public const SansBlack As Typeface = Typeface.LoadFromAssets("SourceSansPro-Black.ttf")
    Public const SansRegular As Typeface = Typeface.LoadFromAssets("SourceSansPro-Regular.otf")

https://www.b4x.com/android/forum/threads/custom-fonts.46461/#content
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
The first step is to load the B4i Font with Font.CreateNew. You can then convert it to a B4XFont with:
B4X:
Dim xfont As B4XFont = xui.CreateFont(Font, 16)
So there is not a general load from assets.. i need something like this?

B4X:
    #If b4a
    Public SansSemibold As B4XFont= xui.CreateFont(Typeface.LoadFromAssets("SourceSansPro-Semibold.otf"), 16)
    #else if b4i
    Public SansSemibold As B4XFont= xui.CreateFont(Font.CreateNew2("SourceSansPro-Semibold", 30), 16)
    #end if
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
So there is not a general load from assets.. i need something like this?
Yes.
It might be added in the future, though there are several nuances here such as the file name vs. the font name.

Remember that XUI library doesn't replace the native libraries. It is intended to work together.
 
Upvote 0
Top