Is there a way to add custom fonts to Xcode to be

2019-07-30 12:41发布

问题:

This question already has an answer here:

  • Designing labels/text views with custom fonts in Interface Builder 8 answers

I know how to add custom font files to be shipped with an iOS app. I can then customize the label font from code using code like this :

UIFont* font = [UIFont fontWithName:@"League Gothic" size:42];
self.topLabel.font = font;

My concern is that such customization will "infect" all of the project and may require some significant rework later on. Is there a way to include a font file into xCode itself, so it recognizes it and lets me select it from the storyboard font control?

回答1:

You can find the answer to this question over here

Designing labels/text views with custom fonts in Interface Builder

You can find a link regarding the same topic here

http://www.abdus.me/ios-programming-tips/set-custom-fonts-in-interface-builder/

Hope this helps you.



回答2:

Another way to achieve it without having to relay on exposing IBOutlets or adding external libraries is using categories and user defined runtime attributes from Storyboard or Interface Builder.

That way you can define your fonts in Storyboard or IB like this:

You can get the code required for the categories from this response.