MLyck
MLyck

Reputation: 5775

changing custom font for UILabel using custom fonts (programatically) in swift

First off, I do realize this has been asked multiple times. Unfortunately the most common answer, isn't working in my case, so please read the full question :)


Here's what I did when I added my custom fonts to the project:

  1. made a folder/group in my project called "Fonts"

  2. added my fonts to that group. (I made sure both the project and "Projetname Tests" was checked as targets)

  3. I checked my project file, -> Build phases -> Copy Bundle resources that the fonts were in there, which they are.

  4. I went to my Plist. and added the group called "Fonts provided by Application", in there I added an item for all my fonts, and changed the strings to the font names

and lastly here's the code that I tried changing the font of a simple label with:

    var label = UILabel(frame: CGRectMake(100, 70, 200, 200))
    label.text = "BE ON THE"
    label.font = UIFont(name: "BabasNeue", size: 106)
    self.view.addSubview(label)

The label shows up when I run the app, but neither the size or the font changes.

if anyone wants to check the fontnames are correct, here's the font I'm trying to use: http://www.fontsquirrel.com/fonts/bebas-NEUE

Lastly, I just want to quickly mention that I am fully able to change the font of any labels to my custom fonts using storyboard. But I cannot get it working through code. :/

Upvotes: 4

Views: 9481

Answers (1)

Christian
Christian

Reputation: 22343

I think you've got a typo. It has to be called BebasNeue but you named it BabasNeue, with an a instead of an e. It needs to be the exact same name as set in the font-file.

Upvotes: 2

Related Questions