Let's say you want to add this font: SourceSansPro-Regular.otf
Four steps:
- Add the font file
SourceSansPro-Regular.otf
to your project, make sure you select your target in the "Add to targets".
Go to the target's Build Phases and make sure it is under Copy Bundle Resources. If not, add it.
2. Go to the target's Info. Add a new entry Font provided by application then add a new item with this value SourceSansPro-Regular.otf
.
- From your finder, double click on the file
SourceSansPro-Regular.otf
, it might ask you to install the font to your Font Book.
- Open the OS X Font Book application, navigate to your font then press Command+i. Note the PostScript name and use that name in your Swift code. In this case, it's
SourceSansPro-Regular
.
So in your code:
labeladd.font = UIFont(name:"SourceSansPro-Regular", size:15)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…