Swift 3应用中Bebas Neue字体异常问题求助
Hey there, I totally get how frustrating it is when only one font weight works while others stay stuck on Regular—let’s walk through the most reliable fixes for this:
Double-check your font files & their internal names
Bebas Neue’s different weights (Light, Thin, Regular) need to be separate font files (likeBebasNeue-Light.ttf,BebasNeue-Thin.ttf). Open each font in Font Book, right-click it and select Show Font Info to get the exact PostScript name (e.g.,BebasNeueLightinstead of "Bebas Neue Light"). This internal name is what iOS actually uses to recognize the font weight.Update your Info.plist
Even if you added fonts via the Identity Inspector, you must list every font file in yourInfo.plist:- Add the key
Fonts provided by application(orUIAppFontsif you prefer the raw key) - Make it an array, then add entries for each font file name (e.g.,
BebasNeue-Light.ttf,BebasNeue-Thin.ttf,BebasNeue-Regular.ttf)
Missing this step is the #1 reason non-Regular weights fail to load.
- Add the key
Verify fonts are actually loaded
Add this quick snippet to yourAppDelegate.swift’sdidFinishLaunchingWithOptionsto print all available fonts to the console:for familyName in UIFont.familyNames { print("Font Family: \(familyName)") for fontName in UIFont.fontNames(forFamilyName: familyName) { print(" - \(fontName)") } }Look for your Bebas Neue Light/Thin entries here. If they don’t show up, your font files aren’t being bundled correctly (double-check they’re added to your target’s Copy Bundle Resources build phase).
Use the exact PostScript name in code/IB
Sometimes the Identity Inspector’s font dropdown uses a display name that doesn’t match the internal PostScript name. If selecting "Bebas Neue Light" in IB doesn’t work, set it via code instead using the name you found in Font Book:yourLabel.font = UIFont(name: "BebasNeueLight", size: 24)Clean & restart Xcode
Xcode loves caching old font data. Do a Clean Build Folder (pressCmd+Shift+K), restart Xcode, and re-run your project to rule out any cached issues.
These steps should get your Light and Thin weights working as expected—most cases boil down to mismatched font names or missing plist configurations.
内容的提问来源于stack exchange,提问作者Jacob Kaif

