xamarin形成小型帽子

时间:2018-01-16 17:26:58

标签: ios xamarin custom-renderer

我的Xamarin Forms应用程序设计师为标签字段指定了小型大写字母。有关如何在Xamarin for Android中执行此操作的几个讨论,但我找不到iOS的任何内容。

我知道我需要一个自定义渲染器,并且已经找到了一个很好的讨论here,但是在将该文章中的Swift代码转换为C#for Xamarin iOS时遇到了挑战。

以下代码:

let systemFont = UIFont.systemFont(ofSize: 24.0, weight: UIFontWeightLight)
let smallCapsDesc = systemFont.fontDescriptor.addingAttributes([
    UIFontDescriptorFeatureSettingsAttribute: [
        [
            UIFontFeatureTypeIdentifierKey: kUpperCaseType,
            UIFontFeatureSelectorIdentifierKey: kUpperCaseSmallCapsSelector
        ]
    ]
])
let font = UIFont(descriptor: smallCapsDesc, size: systemFont.pointSize)

我知道我会在OnElementChanged方法中添加一些内容,但FontDescriptor没有addsAttributes方法或Attributes集合,因此在添加其他属性时遇到了挑战。

1 个答案:

答案 0 :(得分:0)

  

FontDescriptor没有addsAttributes方法或Attributes集合

您正在寻找UIFont.FontDescriptor.CreateWithAttributes方法。

实施例

var systemFont = UIFont.SystemFontOfSize(24, UIFontWeight.Light);
var attributes = new UIFontAttributes(
    new UIFontFeature(CTFontFeatureUpperCase.Selector.UpperCaseSmallCaps),
    new UIFontFeature(CTFontFeatureLowerCase.Selector.LowerCaseSmallCaps)
);
var smallCapsDesc = systemFont.FontDescriptor.CreateWithAttributes(attributes);
var font = UIFont.FromDescriptor(smallCapsDesc, systemFont.PointSize);