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

I have a Maui app where I am successfully using custom fonts. However, in the Maui Toolkit Snackbar, se

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),

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744890432a4599377.html

相关推荐

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

    I have a Maui app where I am successfully using custom fonts. However, in the Maui Toolkit Snackbar, se

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信