Lädt...

🔧 The Mystery of Fonts on iOS: Why Was My App Not Displaying Custom Fonts?


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

A Frustrating Bug on iOS

Recently, while working on a mobile application with React Native and Expo, I encountered an unexpected issue: my custom fonts were not displaying on iOS. Yet, everything worked perfectly on Android.

After hours of debugging and investigation, I discovered that iOS does not recognize fonts by their file name but rather by their "Full Name", a subtlety that does not exist on Android.

In this article, I'll explain the cause of this issue, how to identify it, and most importantly, how to fix it.

Understanding Font Behavior on iOS

On Android, using a custom font is relatively straightforward. You define the font in expo-font using the file path, and it can be referenced directly by its filename:

import { useFonts } from 'expo-font';
import { Text } from 'react-native';

const [fontsLoaded] = useFonts({
  'BasierCircle-Regular': require('./assets/fonts/BasierCircle-Regular.ttf'),
});

if (!fontsLoaded) {
  return null;
}

<Text style={{ fontFamily: 'BasierCircle-Regular' }}>Hello, world!</Text>

Problem: This code does not always work on iOS. The reason is that iOS does not identify fonts by their file name (BasierCircle-Regular.ttf), but rather by their internal font name.

Identifying the Issue

To check which fonts were actually loaded by iOS, I added a simple console.log() in my code:

useEffect(() => {
  console.log('Fonts loaded on iOS:', ExpoFont.getLoadedFonts());
}, []);

The result was surprising:

Fonts loaded on iOS: [
  "BasierCircle-Regular",
  "font000000002d6f7cbc",
  "BasierCircle-SemiBold",
  "SwearDisplay-Bold"
]

Some font names appeared as hexadecimal identifiers (font000000002d6f7cbc) instead of the expected names!

What was happening was that iOS was not using the correct font name but instead generating an identifier.

The Solution: Editing the "Full Name" of the Font

To fix this, I used FontForge, an open-source software that allows you to edit font metadata.

Steps to follow:

  1. Open FontForge and load the font (.ttf or .otf).
  2. Go to Element → Font Info.
  3. Modify the "Full Name" field to match the exact desired name (e.g., BasierCircle-Regular).
  4. Save the font and re-import it into the application.

Proper Integration in Expo

Once the name was corrected, I declared my fonts in app.config.ts (instead of using require() in my code):

export default ({ config }) => ({
  ...config,
  plugins: [
    [
      'expo-font',
      {
        fonts: [
          './assets/fonts/BasierCircle-Regular.ttf',
          './assets/fonts/BasierCircle-Medium.ttf',
          './assets/fonts/BasierCircle-SemiBold.ttf',
          './assets/fonts/BasierCircle-Bold.ttf',
        ],
      },
    ],
  ],
});

This avoids issues related to manually loading fonts and ensures cleaner management via expo-font.

Conclusion

This bug highlights a crucial difference between iOS and Android in handling custom fonts. To avoid this type of issue, here are some best practices to keep in mind:

✅ Always check a font's "Full Name" on iOS using FontForge.

✅ Declare fonts in app.config.ts rather than loading them with require().

✅ Use ExpoFont.getLoadedFonts() to quickly debug font loading.

🚀 With these adjustments, my app now displays fonts correctly on all platforms!

Useful Resources

If you've encountered a similar issue, share your experience in the comments!

...

🔧 The Mystery of Fonts on iOS: Why Was My App Not Displaying Custom Fonts?


📈 73.93 Punkte
🔧 Programmierung

🔧 How to add Google Fonts and Custom Fonts to your Web App


📈 31.33 Punkte
🔧 Programmierung

🔧 How to Implement Custom Fonts using Downloadable Google Fonts?


📈 28.9 Punkte
🔧 Programmierung

🔧 KISS Principle: Giữ Mọi Thứ Đơn Giản Nhất Có Thể


📈 28.59 Punkte
🔧 Programmierung

🔧 Có thể bạn chưa biết (Phần 1)


📈 28.59 Punkte
🔧 Programmierung

🔧 Grok 3: AI Thông Minh Nhất Thế Giới


📈 28.59 Punkte
🔧 Programmierung

🕵️ Kèo Thẻ Phạt Vip66 Là Gì? 3 Lối Đánh Kèo Chậm Mà Chắc


📈 28.59 Punkte
🕵️ Reverse Engineering

🔧 Fix GitHub Achievements Not Displaying on Your Profile


📈 22.78 Punkte
🔧 Programmierung

🔧 React Korean Input Bug: First Character Not Displaying Properly


📈 22.78 Punkte
🔧 Programmierung

🔧 Resolving CSS and HTML Not Displaying in Laravel Hosted Files


📈 22.78 Punkte
🔧 Programmierung

🪟 New Apps not displaying at Top in Shared Channel for Teams


📈 22.78 Punkte
🪟 Windows Tipps

🪟 Fix: Windows 11 Monitor Detected but Not Displaying


📈 22.78 Punkte
🪟 Windows Tipps

🪟 New PC Not Displaying On Monitor: 6 Quick Fixes


📈 22.78 Punkte
🪟 Windows Tipps

🪟 Second monitor not displaying in Windows 11/10 after Update


📈 22.78 Punkte
🪟 Windows Tipps

🐧 I need help with Linux terminal on Chromebook not displaying list


📈 22.78 Punkte
🐧 Linux Tipps

🐧 Second monitor not displaying content correctly


📈 22.78 Punkte
🐧 Linux Tipps

🐧 'ls' not displaying color to terminal


📈 22.78 Punkte
🐧 Linux Tipps

🔧 Why Social Media Platforms Restrict Custom Fonts and Rich Text Formatting


📈 22.18 Punkte
🔧 Programmierung

🐧 Can't load new fonts in programs, but they are there in fonts. (ubuntu)


📈 21.89 Punkte
🐧 Linux Tipps

🐧 Best Linux app displaying lan/wan bandwidth w IPs w alarms?


📈 20.69 Punkte
🐧 Linux Tipps

📰 Aggressive ad-displaying Google Play app tricks users into leaving high ratings


📈 20.69 Punkte
📰 IT Security Nachrichten

🐧 Why the fonts in video when not in full screen are bad and pixelated in my ubuntu.


📈 19.69 Punkte
🐧 Linux Tipps

🪟 Google’s new patent: Future Pixel phones could save battery while displaying images


📈 18.25 Punkte
🪟 Windows Tipps

🔧 Displaying Data from MySQL on the Web: an Introduction


📈 18.25 Punkte
🔧 Programmierung

🔧 Babylon.js Browser MMO - DevLog - Update #3 - Displaying other players


📈 18.25 Punkte
🔧 Programmierung

🪟 Investigation shows Bing displaying, suggesting child pornography


📈 18.25 Punkte
🪟 Windows Tipps

🔧 How we automated displaying error pages based on API responses


📈 18.25 Punkte
🔧 Programmierung

matomo