Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a custom font in storyboard in XCode 6

I want to use an icon font (so far with only one icon) in my iOS 8 Swift project. I first added the font to my project (Add Files to “MyProject” in the file list – and it was then added to my target). I then looked up the character's code point which was U+E600 and inserted U+E600 as a button's title in storyboard. Immediate success – the button now had a nice backspace icon in my storyboard.

However, when I run my app in the simulator, it just shows the infamous questionmark in a square icon.

I then added the following code to my view controller to see if the font was “really added”:

let fontFamilyNames = UIFont.familyNames()
for familyName in fontFamilyNames {
    println("Font Family Name = [\(familyName)]")
    let names = UIFont.fontNamesForFamilyName(familyName as! String)
    println("Font Names = [\(names)]")
}

And sure enough, my font, icomoon appears as a single font in the font family of the same name.

I then opened Info.plist, figuring I might still have to add the font file manually and added icomoon.ttf (the filename is correct) as the first and only item in Fonts provided by application. Re-ran the app. Still a question mark. Ran the app on my iPhone 6 – same behaviour.

To verify that the file is included in the bundle, I opened the Copy bundle resourced under Build Phases for my target and verified that it was listed there.

The font for the button in XCode:

enter image description here

How it looks in the storyboard in XCode:

enter image description here

How it looks in the simulator:

enter image description here

I'm now at a loss of how to proceed. There are lots of guides that vary in how up-to-date they are, but I don't really see anything I've missed. Have I missed something? Any way to debug this issue?

like image 243
beta Avatar asked Nov 16 '25 18:11

beta


1 Answers

I'd suggest grabbing a @IBOutlet reference to the button in code and print out its UIFont. If the font isn't right than perhaps you need to set it programmatically:

yourLabel.font = UIFont(name: "icomoon", size: 20)

I see no problem with the way you have setup your button in interface builder, so it could be a bug or some technicality about the font name.

One thought that comes to mind is that the typical font name is in the form FontFamily-FontName (ex. HelveticaNeue-Regular), whereas your font name isn't like that. Perhaps that has something to do with it.

like image 117
Andrew Avatar answered Nov 19 '25 09:11

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!