3

After updating to Xcode 5.1.1, fontWithName for custom fonts always return nil, which caused crash when setting attributes for atributedString.

I ensured my custom font is in the result of [UIFont familyNames] and fontNamesForFamilyName.

fontWithName works fine if I pass in system font name eg. Helvetica.

If there's any one encountered the same problem? Then how to solve it? Is it a bug in Xcode?

Allen Hsu
  • 3,515
  • 3
  • 25
  • 38
  • check the step 4 in this link http://stackoverflow.com/questions/13798002/setting-size-to-custom-ios-font-doesnt-work/13800169#13800169 – arthankamal Apr 14 '14 at 04:06
  • @arthan.v thanks but I don't think it's the cause. BTW the code works fine until updating to Xcode 5.1.1 – Allen Hsu Apr 14 '14 at 04:15
  • I'm seeing the exact same thing...everything working perfectly (and has been for months with this project)...updated Xcode to 5.1.1 and now custom fonts are failing. I confirmed that the fonts were in the bundle and in the fonts array at runtime...just won't do the fontWithName. – Darren Ehlers Apr 14 '14 at 04:45
  • Have you made sure that your fonts are in the target membership? http://puu.sh/8819G/ec00eb063b.png – Michael King Apr 14 '14 at 05:18
  • 1
    @MichaelKing pretty sure, and I can find the font files in the final `.app` package – Allen Hsu Apr 14 '14 at 05:20
  • I reverted back to Xcode 5.1 and my custom fonts are working fine. It's definitely something that has changed in Xcode 5.1.1... – Darren Ehlers Apr 14 '14 at 19:10
  • @DarrenEhlers I removed all the fonts and rows in `info.plist`, and then add the fonts again, it seems back to normal. – Allen Hsu Apr 15 '14 at 04:57
  • Hmmm...tried removing them and re-adding them, still no change. I can literally exit Xcode 5.1.1, run Xcode 5.1 and it works perfectly. Exit project and switch back, and the fonts don't load. Nothing else changes (confirmed by Git) – Darren Ehlers Apr 15 '14 at 10:07
  • @DarrenEhlers Have you tried creating a new project and add custom fonts in 5.1.1? I firstly created a new project and it works, so I tried re-adding and succeeded. BTW, do you use something like MoarFonts? Once I thought it's related to MoarFonts. – Allen Hsu Apr 15 '14 at 10:13
  • You appear to be correct, it is related to MoarFonts. Looks like the problem is resolved (at least in my case) and I posted an answer below. – Darren Ehlers Apr 15 '14 at 10:40
  • Never used MoarFonts in my life but experiencing the same difficulties after upgrading to 5.1.1 – Mou某 Jun 17 '14 at 11:53

1 Answers1

2

I solved the problem (at least with my install).

I use a program called moarfonts (http://pitaya.ch/moarfonts/).

SOMETHING changed between Xcode 5.1 and Xcode 5.1.1, my guess is that it's related to permissions inside the Xcode.app package.

But, anyway, by following the steps from Solution #2 of the MoarFonts troubleshooting (http://pitaya.ch/moarfonts/#troubleshooting), the problem was resolved and it's working fine now:

export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk
/usr/local/bin/moarfonts reset

YAY! Back to work...

Darren Ehlers
  • 633
  • 6
  • 16
  • Great. In fact, my solution is almost the same, I also reset the moarfonts and then re-added fonts, although I don't know which step did the trick. BTW, I've heard that Xcode 5.1 supports custom fonts in xib, but without moarfonts I cannot see any custom font. – Allen Hsu Apr 16 '14 at 07:33