Custom Font Issue

Hello wonderful solvers of all things xojo! I’m having a bit of a problem using a custom font in an app and was hoping someone might be able to point me in the right direction…

I’ve been following a couple of how-to’s for this, and , and I think I’ve followed all the steps properly, but I still can’t get the font to show.

The code:

[code] Dim classPtr as Ptr = FoundationFramework.NSClassFromString (“UIFont”)

#if Target64Bit
Declare function fontWithName lib UIKitLibName selector “fontWithName:size:” (id as ptr, Fontname as CFStringRef, Size as double) as Ptr
#elseif Target32Bit
Declare function fontWithName lib UIKitLibName selector “fontWithName:size:” (id as ptr, Fontname as CFStringRef, Size as single) as Ptr

Dim f as xojo.IO.FolderItem = SpecialFolder.GetResource(“boston.ttf”)
Dim ft As ptr

If f <> Nil And f.Exists Then

ft = fontWithName(classPtr, "boston", 18) // this returns nil

End If[/code]

I’ve tried the fontWithName function with known non-custom fonts and it works for those fine.

My info.plist (copied into resources folder along with the fonts boston.ttf/boston traffic.ttf in build step):

[code]<?xml version="1.0" encoding="UTF-8"?>

UIAppFonts boston.ttf Boston Traffic.ttf [/code]

As far as I can see I’ve followed the steps, so I’m pretty stumped on what to try next. Any pointers or tips very much appreciated!


Hi Chris,

I think you can find the right font name using the solutions proposed in this thread.

Javier Rodrguez
Evangelista Xojo en Espaol
Autor del Libro “Programacin Multiplataforma Xojo

Jean-Paul, Javier, thank you for your responses!

Logging out the correct name for this font gives “Boston Traffic”. However,

fontWithName(classPtr, "Boston Traffic", 18) is still returning a nil value. I’m pretty lost as to what to try next here. Does anyone have any other tips I could try?


The fontWithName(classPtr, "font name", size) function only seems to work with system fonts.

I’ve tried copying a few different custom fonts into the resources folder and always, the return from fontWithName is nil. The fonts definitely exist in the bundle, and the fontWithName declare works with system fonts, just not custom ones.

My plist file is actually named “info-PROJECTNAME.plist” as when named “info.plist” always results in a

“Compilation of PROJECTNAME failed. An error occurred when attempting to launch the application.”

Could that have something to do with it, an incorrectly named plist? I’m about ready to renounce technology…!


I was copying my plist in a build step, rather than including it in the project.

this post showed me the way.