iOS Question Custom Fonts Problem

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone.
I'm trying to use these fonts (attached), i put this in "#Region Project Attributes"

B4X:
    #AppFont: futuralt-bold.ttf
    #AppFont: futuralt-book.ttf
    #AppFont: futuralt-bookoblique.ttf

i put the .ttf in the Special folder, and did like so:


B4X:
    lblTitleLastOps.Font = Font.CreateNew2("FuturaLTBold", 30)

I got this error:

B4X:
Application_Start
Application_Active
Error occurred on line: 51 (Home)
Object was not initialized (UIFont)
Stack Trace: (
  CoreFoundation       727F2644-EB4E-3D57-BC2E-E6803BA92366 + 1202304
  libobjc.A.dylib      objc_exception_throw + 60
  CoreFoundation       727F2644-EB4E-3D57-BC2E-E6803BA92366 + 124068
  AppTest              -[B4IObjectWrapper object] + 136
  AppTest              -[B4ILabelWrapper setFont:] + 72
  AppTest              -[b4i_home _initialize] + 1028
  AppTest              -[ResumableSub_main_ControlloBlocco resume::] + 5572
  CoreFoundation       727F2644-EB4E-3D57-BC2E-E6803BA92366 + 1222900
  CoreFoundation       727F2644-EB4E-3D57-BC2E-E6803BA92366 + 7672
  AppTest              +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
 AppTest              -[B4IShell runMethod:] + 448
 AppTest              -[B4IShell raiseEventImpl:method:args::] + 2172
 AppTest              -[B4IShellBI raiseEvent:event:params:] + 1580
 AppTest              -[B4IDelegatableResumableSub resume::] + 380
 AppTest              -[B4I checkAndRunWaitForEvent:event:params:] + 516
 AppTest              -[B4IShellBI raiseEvent:event:params:] + 1436
 AppTest              __37-[B4ICommon ReturnFromResumableSub::]_block_invoke + 368
 libdispatch.dylib    B92757B1-0434-3E9B-A3AC-B6DA6B81945C + 8780
 libdispatch.dylib    B92757B1-0434-3E9B-A3AC-B6DA6B81945C + 15792
 libdispatch.dylib    _dispatch_main_queue_callback_4CF + 836
 CoreFoundation       727F2644-EB4E-3D57-BC2E-E6803BA92366 + 659740
 CoreFoundation       727F2644-EB4E-3D57-BC2E-E6803BA92366 + 635168
 CoreFoundation       CFRunLoopRunSpecific + 600
 GraphicsServices     GSEventRunModal + 164
 UIKitCore            8518EAE3-832B-3FF0-9FA5-9DBE3041F26C + 12357352
 UIKitCore            UIApplicationMain + 168
 AppTest              main + 128
 libdyld.dylib        21B19919-1334-38BC-B233-896E929945E0 + 5808
)
Class (b4i_xml2map) instance released.
Class (b4i_httpjob) instance released.

What could be the issue? Thanks in advance
 

Attachments

  • FuturaLT.zip
    38.8 KB · Views: 269

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
actually following this tutorial took me to having the problem.

Because 4th step the tutorial says to use the font name without spaces, and I did (I used the name showed in the Windows title bar when you open a .ttf file) and It didn't work.
To get it working, in this case only, I had to use the filename (apparently), like angel_ suggested, even if I don't know why, because all the other times it worked using the font name, not the filename.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
You can use a snippet (for example, in Application_Start), to understand, what IOS expects.

B4X:
    Dim no As NativeObject
    Dim l1 As List = no.Initialize ("UIFont").GetField ("familyNames")
    For Each s1 As String In l1
        Log (s1)
        Dim l2 As List = no.Initialize ("UIFont").RunMethod ("fontNamesForFamilyName:", Array (s1))
        For Each s2 As String In l2
           Log ("   " & s2)
        Next
    Next

In your case you will see for family name Futura LT following font names:
B4X:
   FuturaLT-Book
   FuturaLT-BookOblique
   FuturaLT-Bold
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
You can use a snippet (for example, in Application_Start), to understand, what IOS expects.

B4X:
    Dim no As NativeObject
    Dim l1 As List = no.Initialize ("UIFont").GetField ("familyNames")
    For Each s1 As String In l1
        Log (s1)
        Dim l2 As List = no.Initialize ("UIFont").RunMethod ("fontNamesForFamilyName:", Array (s1))
        For Each s2 As String In l2
           Log ("   " & s2)
        Next
    Next

In your case you will see for family name Futura LT following font names:
B4X:
   FuturaLT-Book
   FuturaLT-BookOblique
   FuturaLT-Bold

thanks very much Semen, this will be useful in future.
 
Upvote 0
Top