阅读:178 点赞:1 评论:0
178
Xamarin 内得字体大小其实每个手机显示都不一样,在设置得时候感觉很恶心,毕竟不是多少像素点或者高度得表达得方式。
设置字体属性
显示文本的控件可以设置 FontAttributes 属性以指定字体属性:
等效 C# 代码如下:
Label label1 = new Label
{
Text = "Italics",
FontAttributes = FontAttributes.Italic
};
Label label2 = new Label
{
Text = "Bold and italics",
FontAttributes = FontAttributes.Bold | FontAttributes.Italic
};
设置字号
显示文本的控件可以设置 FontSize 属性以指定字体大小。 FontSize属性可以直接设置为 double 值,也可以设置为 枚举 NamedSize 值:
等效 C# 代码如下:
Label label1 = new Label
{
Text = "Font size 24",
FontSize = 24
};
Label label2 = new Label
{
Text = "Large font size",
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
};
设置每个平台的字体属性
和 OnPlatformOn 类可在 XAML 中用于设置每个平台的字体属性。 以下示例在每个平台上设置不同的字体系列和大小:
Device.RuntimePlatform属性可在代码中用于设置每个平台的字体属性
Label label = new Label
{
Text = "Different font properties on different platforms"
};
label.FontSize = Device.RuntimePlatform == Device.iOS ? 20 :
Device.RuntimePlatform == Device.Android ? Device.GetNamedSize(NamedSize.Medium, label) : 24;
label.FontFamily = Device.RuntimePlatform == Device.iOS ? "MarkerFelt-Thin" :
Device.RuntimePlatform == Device.Android ? "Lobster-Regular" : "ArimaMadurai-Black";
了解命名字号
Xamarin.Forms 定义枚举中 NamedSize 表示特定字体大小的字段。 下表显示了 iOS、Android 和 Universal Windows Platform (NamedSize UWP) :
特别是这个字号,非常常用,记住名字比记住数字好使
度量单位
Android、iOS 和 UWP 平台都有不同的度量单位,这些度量单位可能因设备而异。 Xamarin.Forms 使用独立于平台的度量单位,该度量单位跨设备和平台规范化单位。 中每英寸 160 个单位,或每厘米 64 个单位 Xamarin.Forms 。
编写于:2022/1/15 13:46:24
发布 IP 属地:
版权声明
编写于:2022/1/15 13:46:24
发布 IP 属地:
本站内容均来自网络转载或网友提供,如有侵权请及时联系我们删除!本站不承担任何争议和法律责任!