【问题标题】:How to programmatically set accessibilityLabel on UILabel?如何以编程方式在 UILabel 上设置accessibilityLabel?
【发布时间】:2019-06-08 18:27:04
【问题描述】:

我正在尝试在我的 UIViewController 中以编程方式为 UILabel(标题为“Mega Title!”)设置可访问性标签和值。这是我的 viewDidLoad...

- (void)viewDidLoad {
    [super viewDidLoad];

    // seems you can only set value on UILabel
    self.powLabel.isAccessibilityElement = YES;
    self.powLabel.accessibilityLabel = @"lbl label";    // sets value ???
    self.powLabel.accessibilityValue = @"lbl value";    // this doesn't work.

    // you can set title and value on UIView
    self.powView.isAccessibilityElement = YES;
    self.powView.accessibilityLabel = @"view label";    // sets title
    self.powView.accessibilityValue = @"view value";    // sets value


    // you can set title and value on UIButton
    self.powButton.isAccessibilityElement = YES;
    self.powButton.accessibilityLabel = @"btn label";    // sets title
    self.powButton.accessibilityValue = @"btn value";    // this value   
}

在 UIView 和 UIButton 控件中正确设置了可访问性标题/值...但是只有在 UILabel 控件上设置了可访问性值。这是辅助功能检查器显示的屏幕截图...

如何设置 UILabel 以使 accessibilityLabel 实际上具有值?

【问题讨论】:

  • 你想从无障碍价值中获得什么?
  • 我需要让盲人用户知道 A-标签的标题和 B-标签的值是什么。
  • 尝试无障碍提示
  • Yessir - 已经尝试过了,它似乎不会影响accessibilityLabel 或accessibilityValue 值。

标签: ios objective-c cocoa-touch uilabel uiaccessibility


【解决方案1】:

UILabel 将在其上使用.text 设置文本作为accessibilityLabel,这取决于您想要做什么我认为最好使用accessibilityIdentifier 来识别UI 元素并保留默认值。

【讨论】:

  • 我还尝试设置accessibilityIdentifier...这似乎没有为上述任何(UILabel、UIView、UIButton)控件设置标签或值。
【解决方案2】:

在模拟器上检查应用程序内视图的可访问性时,您需要确保选择模拟器作为当前上下文,而不是您的计算机。单击左上角的当前选择会显示一个下拉菜单。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 2010-11-21
    • 2016-07-28
    • 1970-01-01
    相关资源
    最近更新 更多