最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

maui - How do I use a custom font? - Stack Overflow

programmeradmin3浏览0评论

I have a Maui app where I am successfully using custom fonts. However, in the Maui Toolkit Snackbar, setting the font is done with a font object, not the string for font family.

How can I load up a Font object from my custom font?

    var snackbarOptions = new SnackbarOptions
    {
        // this is how you set the font according to samples
        Font = Microsoft.Maui.Font.SystemFontOfSize(14),
        // FontFamily is not valid. Custom fonts are usually set like this
        FontFamily = "MyCustomFont" 
    };

I have a Maui app where I am successfully using custom fonts. However, in the Maui Toolkit Snackbar, setting the font is done with a font object, not the string for font family.

How can I load up a Font object from my custom font?

    var snackbarOptions = new SnackbarOptions
    {
        // this is how you set the font according to samples
        Font = Microsoft.Maui.Font.SystemFontOfSize(14),
        // FontFamily is not valid. Custom fonts are usually set like this
        FontFamily = "MyCustomFont" 
    };
Share Improve this question edited Mar 11 at 7:34 DarkBee 15.5k8 gold badges72 silver badges118 bronze badges asked Mar 8 at 17:11 Mr WMr W 6761 gold badge9 silver badges25 bronze badges 2
  • What platform did you target? – Liyun Zhang - MSFT Commented Mar 10 at 5:02
  • iOS but that doesn't matter. this is a coding issue, not including the actual font resource – Mr W Commented Mar 10 at 15:54
Add a comment  | 

2 Answers 2

Reset to default 0

As you see:

    // this is how you set the font according to samples  
    Font = Microsoft.Maui.Font.SystemFontOfSize(14)

And I have check the source code about the Microsoft.Maui.Font, the font family is read-only. So you can set it as a custom font.

In addition, I also checked the source code about the ios platform snackbar. There is no override method can custom it.

You can open a feature request on the CommunityToolkit/Maui repo.

Found the solution:

Font = Font.OfSize("MyCustomFontName", 14),

发布评论

评论列表(0)

  1. 暂无评论