Is there a way to add custom fonts to Xcode to be available from a storyboard? [duplicate]

别等时光非礼了梦想. 提交于 2020-01-05 10:13:09

问题


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.



来源:https://stackoverflow.com/questions/17278395/is-there-a-way-to-add-custom-fonts-to-xcode-to-be-available-from-a-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!