更改每个屏幕尺寸xamarin形式的标签大小

Joy*_*nna 5 c# layout xaml xamarin xamarin.forms

我正在使用xamarin.forms来做一个应用程序我觉得使用相同的大小来写信给ios设备是行不通的:在7加上它运行良好,但在iPhone 5上它是一个大字母的屏幕大小...有人知道如何使用可伸缩大小的字母,或更改特定设备或屏幕大小类型的大小?非常感谢你.

Sha*_*raj 5

您可以参考以下样本:

  1. 估计字体大小以获得视觉一致性 - (docs | github)

    // Resolution in device-independent units per inch.
    double resolution = 160;
    
    // Do some numeric point sizes.
    int[] ptSizes = { 4, 6, 8, 10, 12 };
    
    // Select numeric point size you need from ptSize[] array 
    double ptSize = 4;
    
    // this is your new visually consistent font-size.
    var fontSize = resolution * ptSize / 72; 
    
    Run Code Online (Sandbox Code Playgroud)
  2. 将文本拟合为可用大小 - (docs | github)

    double lineHeight = Device.OnPlatform(1.2, 1.2, 1.3);//TODO: Change this to Device.RuntimePlatform
    double charWidth = 0.5;
    
    int charCount = text.Length;
    
    var view = this.Parent;
    // Because:
    //   lineCount = view.Height / (lineHeight * fontSize)
    //   charsPerLine = view.Width / (charWidth * fontSize)
    //   charCount = lineCount * charsPerLine
    // Hence, solving for fontSize:
    int fontSize = (int)Math.Sqrt(view.Width * view.Height /
                        (charCount * lineHeight * charWidth));
    
    Run Code Online (Sandbox Code Playgroud)

  • 恕我直言,这不能回答问题。#2 是另一种情况。#1 对不同物理尺寸的屏幕没有帮助。转换为磅值与 Xamarin Forms 无关。 (2认同)