MAUI Custom Font – Working on android, not on iOS

I’ve updated a font within a MAUI app, but it only loads on Android and not iOS with no errors appearing in the Application console. This occurs both on the simulator and on devices.

The app runs whilst in debug on iOS without the setup fonts, but crashes when run in release mode. The simulators console doesn’t seem to give any indication as to why the crash happens, and nothing jumps when looking through the build log with the Structured Log Viewer/

I’ve used the fontbook on Mac to verify the font, installed it successfully on the laptop, and deleted some build / cache things:

  • Clean / Rebuild
  • Deleted Bin/Obj
  • Deleted the app from devices/simulators
  • Cleared Xcode Caches
  • Reset simulators

Any help with pinning down why this font won’t work, how to debug further, or an alternative way to load the fonts, would be much appreciated. Thanks is advance.

The Detail

Font’s are dragged and dropped into the Visual Studio Mac interface:

These font’s are loaded into the app in .csproj via the following, plus an un-shown attempt to explicitly add each font:

<ItemGroup>
    <MauiFont Include="ResourcesFonts*" />
</ItemGroup>

Any auto added <None Remove=". . . " /> statements are deleted from the file, and after setting the build action to MAUIFont, and “copy to output directory”, the following is added to the .csproj for each of the fonts.

<ItemGroup>
    <MauiFont Update="ResourcesFontsManrope-Regular.ttf">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </MauiFont>
</ItemGroup>

These fonts are then loaded into the app via MauiProgram.cs:

.ConfigureFonts(fonts => {
    fonts.AddFont("Manrope-Regular.ttf", "SecondaryRegular");
    fonts.AddFont("Manrope-Bold.ttf", "SecondaryBold");
    fonts.AddFont("Manrope-ExtraBold.ttf", "SecondaryBlack");

    foreach (var f in fonts)
    {
        Debug.WriteLine($"Font: {f.Filename} / {f.Alias}");
    }
});

The debug statement prints:

Font: Manrope-Regular.ttf / SecondaryRegular 
Font: Manrope-Bold.ttf / SecondaryBold 
Font: Manrope-ExtraBold.ttf / SecondaryBlack

The font is used throughout the app from Resources/Raw/Styles.xaml, for example:

<Style TargetType="Button" x:Key="FullWidthButton">
    <Setter Property="FontFamily" Value="SecondaryRegular"/>
</Style>

This is the point at which I’d expect this to work, and did so with other fonts previously. And it does with this one on Android, but not on iOS.

From Platforms/iOS/AppDelegate.cs, I can check if the font’s are available to the app once it’s fully loaded.

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    foreach (var item in UIFont.FamilyNames)
    {
        Debug.WriteLine($"Font Family: {item}");
        Debug.WriteLine($"Font Names: {string.Join(", ", UIFont.FontNamesForFamilyName(item))}");
    }
}

Which prints out:

Font Family: Manrope
Font Names: Manrope-Regular, Manrope-Bold, Manrope-ExtraBold

I can also instantiate a new label using the font from platform code, at which point I’d expect some complaints in the Debug Console.

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{

    var font = UIFont.FromName("Manrope-Regular", 16);
    Debug.WriteLine($"Font: {font}"); // Prints out  "Font: Manrope-Regular 16"
    var label = new UILabel
    {
        Text = "Hello, Maui!",
        Font = font,
        . . .
    };
    Debug.WriteLine($"Font: {font}");
}

For fun, I also added the font directly to the Platforms/iOS/Info.plist file with no joy, but I didn’t expect that this was needed anyway.

<key>UIAppFonts</key>// OR //<key>Fonts provided by application</key>
<array>
    <string>Manrope-Bold.ttf</string>
    <string>Manrope-Regular.ttf</string>
    <string>Manrope-ExtraBold.ttf</string>
    <string>CrimsonProBold.ttf</string>
    <string>CrimsonProRegular.ttf</string>
</array>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật