我正在使用新的UIAlertController来显示警报.我有这个代码:
// nil titles break alert interface on iOS 8.0, so we'll be using empty strings
UIAlertController *alert = [UIAlertController alertControllerWithTitle: title == nil ? @"": title message: message preferredStyle: UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle: cancelButtonTitle style: UIAlertActionStyleCancel handler: nil];
[alert addAction: defaultAction];
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
[rootViewController presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
现在我想更改标题和消息字体,颜色,大小等.什么是最好的方法呢?
编辑: 我应该插入整个代码.我为UIView创建了一个类别,我可以为iOS版本显示正确的警报.
@implementation UIView (AlertCompatibility)
+( void )showSimpleAlertWithTitle:( NSString * )title
message:( NSString * )message
cancelButtonTitle:( NSString * )cancelButtonTitle
{
float iOSVersion = [[UIDevice currentDevice].systemVersion floatValue]; …Run Code Online (Sandbox Code Playgroud) 首先是的,我见过这个问题,但目前没有答案。
根本问题是我目前XCUITesting是本地化的应用程序,因此UIAlertActions 已本地化,因此我找不到按钮。
我可以做一个 hack,其中我将包含Localizable.strings我的 UITesting 包中的所有内容,然后在尝试获取这样的按钮时获取本地化版本。
let localizedAlertTitle = ...(some function to fetch localized name)
let localizedButtonName = ...(some function to fetch localized name)
self.app
.alerts[localizedAlertTitle]
.buttons[localizedButtonName]
.tap()
Run Code Online (Sandbox Code Playgroud)
另一种方法是可能做这个如此回答所说的黑客,但它太hacky并且有样板。
有没有办法accessibilityIdentifier在 UIAlertAction 上设置?