ios – 如何将`accessibilityLabel`添加到`UIAlertView`按钮?

如何将accessibilityLabel添加到UIAlertView按钮?
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Announcement" 
                                                message: @"message!"
                                               delegate: nil    
                                      cancelButtonTitle: @"cancelButton"  
                                      otherButtonTitles: @"otherButton"]; 

[alert show];

解决方法

唯一可以做到这一点的方法是在UIAlertView子视图中找到UIButtons:
for (id button in self.alertView.subviews){
    if ([button isKindOfClass:[UIButton class]]){
        ((UIButton *)button).accessibilityLabel = @"your custom text";
    }
}

但是这是唯一的方法,因为没有公共API来访问这些UIButton,这是因为Apple不希望您访问它们.访问UIAlertView类的内部视图是Apple不允许的,并且很可能会在App Store审核过程中拒绝您的应用.

如果您确实需要具有自定义accessibilityLabel的UIButtons,您应该考虑设计自定义警报视图而不是使用Apple UIAlertView类.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...