根据屏幕大小自定义命名字体大小 [英] Customize named font sizes depending on the screen-size

查看:43
本文介绍了根据屏幕大小自定义命名字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 xamarin.forms 应用程序中,如何根据默认字体的屏幕大小自定义命名字体大小对我不起作用?

In a xamarin.forms app, how could I customize named font sizes depending on the screen-size for the default ones don't work for me?

mainScale.LabelFontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)) * 2.5;

我对 2.5 进行了硬编码,因为它看起来更好.

I've hardcoded 2.5 because it looks better.

能否请您告诉我如何将这些硬编码的内容更改为跨平台应用程序中的动态因素?

Could you please let me know how I could have these hardcoded ones changed to a dynamic factor in a cross-platform app?

推荐答案

我遇到了 Allan Ritchie 提供的跨平台屏幕分辨率解决方案 GitHub 链接,nuget 包是 Nuget 链接

I have come across a cross-platform screen resolution solution given by Allan Ritchie GitHub link and the nuget package is Nuget link

在共享的 .net 标准库中,在相应的 ContentView 中,以下代码有效:

In the shared .net standard library, in the respective ContentView, the below code works:

    protected override void OnSizeAllocated(double width, double height)
    {
        // specific font adjustment code goes here
        if (CrossDevice.Hardware.ScreenHeight > 600)
        {
        ...              
        }
        ...

        base.OnSizeAllocated(width, height); //must be called
    }

这篇关于根据屏幕大小自定义命名字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆