You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法为UITableViewCell中的Label设置Century Gothic字体求助

Fixing Century Gothic Font Not Working in UITableViewCell

Hey there, let’s work through this frustrating font issue together! It’s so annoying when you’ve tried both Storyboard and code to set a custom font, but it still sticks to the default Avenir. Here are the key fixes to get Century Gothic working properly:

1. Double-Check Font Import & Info.plist Setup

First off, make sure the font is actually properly added to your project:

  • Confirm the Century Gothic font file (.ttf or .otf) is in your Xcode project, and that its Target Membership is checked for your main app target (you can find this in the File Inspector on the right when selecting the font file).
  • Open your Info.plist and verify you have the Fonts provided by application key (add it if missing). Add the exact filename of your Century Gothic font(s) to the array under this key—pay close attention to capitalization and spacing (e.g., CenturyGothic.ttf or CenturyGothic-Bold.ttf). Typos here are one of the most common causes of font failures.

2. Use the Correct Font Name (Not Just the Filename)

The system’s internal name for the font might not match the filename or the display name you see in Storyboard. To find the exact name Century Gothic uses:
Add this quick debug code to your app’s launch cycle (like application(_:didFinishLaunchingWithOptions:) or a view controller’s viewDidLoad()):

for family in UIFont.familyNames.sorted() {
    let fontNames = UIFont.fontNames(forFamilyName: family)
    print("Family: \(family) → Fonts: \(fontNames)")
}

Run your app, look for "Century Gothic" in the family list, and use the exact font name from the output (it might be CenturyGothic without spaces). Update your code to use this name, e.g.:

cell.foodTitle.font = UIFont(name: "CenturyGothic", size: 58)

3. Troubleshoot Storyboard Attributed Text Settings

If you’re using Attributed Text in Storyboard:

  • Double-check that you’ve selected the correct Century Gothic variant (not a similar-named font) in the font picker.
  • Clean your project (press Cmd+Shift+K) and rebuild—sometimes Storyboard caches old font settings.
  • Ensure there are no Font Overrides in the Size Inspector that might be overriding your custom font selection.

4. Make Sure Code Settings Aren’t Being Overridden

Check your custom UITableViewCell1 class:

  • Look for any code in awakeFromNib() or layoutSubviews() that sets the foodTitle font—this could be overwriting the font you set in cellForRowAt.
  • Verify that your foodTitle IBOutlet is connected to the correct label in the cell, not a different one.

5. Test Font Loading Success

Add a quick check to confirm if the font is loading properly in your cellForRowAt method:

if let customFont = UIFont(name: "CenturyGothic", size: 58) {
    cell.foodTitle.font = customFont
} else {
    print("⚠️ Failed to load Century Gothic font!")
    // Fallback to a system font if needed
    cell.foodTitle.font = UIFont.systemFont(ofSize: 58)
}

If you see the error print statement, go back to steps 1 and 2—your font isn’t being recognized by the app.


内容的提问来源于stack exchange,提问作者kitchen800

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:26:50