Lud*_*uda 6 accessibility objective-c uialertview ios
如何添加accessibilityLabel到UIAlertView按钮?
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Announcement"
message: @"message!"
delegate: nil
cancelButtonTitle: @"cancelButton"
otherButtonTitles: @"otherButton"];
[alert show];
Run Code Online (Sandbox Code Playgroud)
执行此操作的唯一方法是在 UIAlertView 子视图中查找 UIButton:
for (id button in self.alertView.subviews){
if ([button isKindOfClass:[UIButton class]]){
((UIButton *)button).accessibilityLabel = @"your custom text";
}
}
Run Code Online (Sandbox Code Playgroud)
然而,这是唯一的方法,因为没有公共 API 来访问这些 UIButton,这是因为 Apple 不希望您访问它们。Apple 不允许访问 UIAlertView 类的内部视图,这很可能会使您的应用程序在 App Store 审核过程中被拒绝。
如果您确实需要具有自定义accessibilityLabel 的UIButtons,您应该考虑设计一个自定义警报视图,而不是使用Apple UIAlertView 类。