How to Change Font Style in Swift

Collin O. picture Collin O. · Dec 4, 2015 · Viewed 25k times · Source

I'm trying to figure out how to change the style of a font to "Thin". Does anyone know how to do this?

Here's my best try, but it doesn't work:

m.font = UIFont(name: "Apple SD Gothic Neo", style: "Thin", size: 8.0)

Answer

Caleb Kleveter picture Caleb Kleveter · Dec 4, 2015

The way I have seen it is AppleSDGothicNeo-Thin, No spaces, and a dash style. So your code would be

m.font = UIFont(name: "AppleSDGothicNeo-Thin", size: 8.0)

Edit:

I have come to understand why you use the font this way.

If you add a custom font to your project, it has a name of "SuperAwesomeFont-Light.ttf". So it makes sense that you just use the file name for the name of the font.