Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Mark Lyck
Courses Plus Student 1,784 PointsIssues with changing font for UILabel using custom fonts (programatically)
Hello,
I'm having some trouble changing the font of my UILabel through code.
Here's what I did when I added my custom fonts to the project:
made a folder/group in my project called "Fonts"
added my fonts to that group. (I made sure both the project and "Projetname Tests" was checked as targets)
I checked my project file, -> Build phases -> Copy Bundle resources that the fonts were in there, which they are.
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, 21))
label.text = "BE ON THE"
label.font = UIFont(name: "Babas Neue-Bold", 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. :/
1 Answer
Mark Lyck
Courses Plus Student 1,784 PointsNevermind I fixed the issue, I had a type in the fontname. As it's called "Bebas Neue" not "BabasNeue"