ttf fonts added in class library project cannot be found in iOS 15.0

Navaneeth 21 Reputation points
2022-01-12T10:27:44.683+00:00

I have ttf fonts added in the "Resources" folder of the iOS project of a Xamarin.Forms class library project. I am using the ttf fonts to render toolbar icons in my library. I have added this class library as a reference to an application project.

But when the application is run, the fonts are not available. The below code returns null.

string resourcePath = NSBundle.MainBundle.PathForResource("FontName", "ttf");

The build action of the ttf files are BundleResource. The fonts are available only if I copy the ttf files to the "Resources" folder of the iOS project of the application.

This problem occurs only in iOS versions > 15.0. Below 15.0, the fonts from the class library are loaded without any problem. Is there a way to resolve this problem?

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2022-01-13T09:23:19.253+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    You could trying create an iOS class library project and add the font to "Resources" folder. Then add this reference to your application project, the resourcePath won't be null.

    I'm afriad your library project is a Portable Class Librariy (PCL), it was deprecated. If you have any other issues, feel free to let me know.

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.