Font not loading in XCode

…衆ロ難τιáo~ 提交于 2019-12-06 15:02:56

问题


Well, I want to import a new Font to my application but without success. I have the Fonts provided by application key in my .plist , I have my font in the Item 0 as a String and the value AdelleBasic_Bold.otf, I have added that Font to my project, and I am trying to use it with:

_myTextField.font = [UIFont fontWithName:@"Adelle Basic" size:15];

Adelle Basic is the header of the Font when I open it. I have also tried without any success:

_myTextField.font = [UIFont fontWithName:@"AdelleBasic_Bold" size:15];

Any suggestion?


回答1:


This may well not true for all fonts, but in my experience, Xcode can be fussy, & I've never been able to get it to use otf fonts (anyone who has please post!), so I've always converted my fonts using this really excellent website - Online Font Converter

I convert them to ttf fonts, and they always seem to work fine - make sure you use the exact name (changing the filename of the font seems to stop it working too).

Hope this helps.




回答2:


Below is the proper way to add fonts to your XCODE app (.otf fonts work fine):

  1. Include your fonts in your XCode project
  2. Make sure that they’re included in the target
  3. Double check that your fonts are included as Resources in your bundle
  4. Include your iOS custom fonts in your application plist
  5. Find the name of the font

Credits and better explaination with images here




回答3:


you can use only the third party fonts which have extension as ttf and the fonts which have otf extension will not work effectively and mostly doesn't work




回答4:


Apart from assuring the 5 points, you could also try out the following snippet of code that prints out the installed fonts:

for (NSString* family in [UIFont familyNames])
{   
    NSLog(@"%@", family)       
    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
        NSLog(@"  %@", name);
    }
}

If the font that you want to use is not listed, then you missed in some of the 5 steps.




回答5:


I just add font into project, check if font will copy inside bundle. Set up it on my Mac and directly use font inside Interface Builder. If you will have any problems solve they here.



来源:https://stackoverflow.com/questions/10170476/font-not-loading-in-xcode

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