我正在使用 xamarin.forms 来做一个应用程序,我发现使用相同的大小来向 ios 设备发送字母是行不通的:在 7 plus 上它运行良好,但在 iphone 5 上它对于屏幕大小来说是一个大字母...
有人知道如何制作具有可缩放尺寸的字母,或者更改特定设备或屏幕尺寸类型的尺寸吗?
非常感谢。
您可以参考以下示例:
-
估计字体大小以保持视觉一致性 - (docs https://developer.xamarin.com/guides/xamarin-forms/creating-mobile-apps-xamarin-forms/summaries/chapter05/#Estimated_font_sizes |
github https://github.com/xamarin/xamarin-forms-book-samples/blob/master/Chapter05/FontSizes/FontSizes/FontSizes/FontSizesPage.cs#L53)
// 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;
-
将文本调整为可用大小 - (docs https://developer.xamarin.com/guides/xamarin-forms/creating-mobile-apps-xamarin-forms/summaries/chapter05/#Fitting_text_to_available_size |
github https://github.com/xamarin/xamarin-forms-book-samples/blob/master/Chapter05/EstimatedFontSize/EstimatedFontSize/EstimatedFontSize/EstimatedFontSizePage.cs#L51)
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));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)