更改每个屏幕尺寸的Xamarin表格的标签大小 [英] Change label size per screen size xamarin forms
本文介绍了更改每个屏幕尺寸的Xamarin表格的标签大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用xamarin.forms来做一个应用程序,但我发现使用相同的大小向ios设备发送信是行不通的:在7以上的版本上它能很好地工作,但在iphone 5上,对于该大小来说这是一个很大的字母屏幕的... 有人知道用可调用的大小写字母的方法,还是更改特定设备的大小或屏幕大小类型的方法? 非常感谢你.
I'm using xamarin.forms to do an app and I perceived that to use the same size to letter to ios devices is not working: on 7 plus it works well, but on iphone 5 it's a Big letter for the size of the screen... Do someone know a way to do letter with scallable size, or change the size for a specific device or type of screen size? Thank you very much.
推荐答案
您可以参考以下示例:
-
估计字体大小以保持视觉一致性-( 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;
将文本调整为可用大小-( github )
Fitting text to available size - (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));
这篇关于更改每个屏幕尺寸的Xamarin表格的标签大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文