我想使用UIAccessibility非正式协议在MonoTouch中的某些视图上设置辅助功能特征。但是没有约束力。我怎么能这样做?
答案 0 :(得分:1)
可以使用MonoTouch UIResponder.SetValueForKey(键,值)调用。以下是一些扩展方法,用于获取和设置控件的可访问性特征:
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发布了一些其他与辅助功能相关的扩展方法here。它们允许您为控件设置辅助功能标签和提示。