1

我想使用UIAccessibility非正式协议在 MonoTouch 中的某些视图上设置可访问性特征。但是没有绑定。我怎样才能做到这一点?

4

1 回答 1

1

可以使用 MonoTouch UIResponder.SetValueForKey(key,value) 调用。以下是一些获取和设置控件的可访问性特征的扩展方法:

public static void SetAccessibilityTraits(this UIResponder responder, UIAccessibilityTraits traits)
{
    responder.SetValueForKey(NSNumber.FromUInt64((ulong)traits), new NSString("accessibilityTraits"));
}

public static UIAccessibilityTraits GetAccessibilityTraits(this UIResponder responder)
{
    var value = (NSNumber)responder.ValueForKey(new NSString("accessibilityTraits"));
    return (UIAccessibilityTraits)value.UInt64Value;
}

[Flags]
public enum UIAccessibilityTraits
{
    None = 0,
    Button = 1,
    Link = 2,
    SearchField = 1024,
    Image = 4,
    Selected = 8,
    PlaysSound = 16,
    KeyboardKey = 32,
    StaticText = 64,
    SummaryElement = 128,
    NotEnabled = 256,
    UpdatesFrequently = 512,
    StartsMediaSession = 2048,
    Adjustable = 4096,
    AllowsDirectInteraction = 8192,
    CausesPageTurn = 16384,
    Header = 65536    
}

Nic Wise 在此处发布了一些其他与可访问性相关的扩展方法。它们允许您为控件设置可访问性标签和提示。

于 2012-10-27T00:20:42.977 回答