UIFont with custom font fails with Nil

后端 未结 7 1970
孤街浪徒
孤街浪徒 2020-12-31 10:59

I\'m trying to add a custom font to my project in Xcode 4.2, but whenever I try to use it, I get a error that the object is nil.

I have done the following:
1) Ad

7条回答
  •  無奈伤痛
    2020-12-31 11:28

    Have you put a breakpoint in and checked that you are getting a valid UIFont object for myFont. This is worth checking as most likely the issue is that "LCDMono2 Ultra" is actually the font family name and what you want to be using is something like "LCDMono2 Ultra-normal" or "LCDMono2 Ultra-bold". Open your .ttf with Font Book and see what info it gives you.

    Alternatively if you can't find anything in Font Book you could try calling:

    NSArray *fonts = [UIFont fontNamesForFamilyName:"LCDMono2 Ultra"];
    

    And then just printing the array fonts in the debugger to check what they should be.

    Hope this help, let me know if this doesn't work and i'll try to think of something else :)

提交回复
热议问题