AHAlertView
是 UIKit 的 UIAlertView
的强大、基于块的替代品。它具有以下吸引人的特点:
UIAppearance
以允许轻松定制所有元素显示一个警报就像创建一个警报,添加一个按钮,然后调用 show
AHAlertView *alert = [[AHAlertView alloc] initWithTitle:@"Hello, World!" message:@"I'm an alert view!"];
[alert setCancelButtonTitle:@"Dismiss" block:nil];
[alert show];
如果添加了两个按钮,则警报视图将将它们并排布局
AHAlertView *alert = [[AHAlertView alloc] initWithTitle:@"Enter Password" message:@"This is a message that might prompt you to do something."];
[alert setCancelButtonTitle:@"Cancel" block:nil];
[alert addButtonWithTitle:@"OK" block:nil];
[alert show];
您可以使用警报视图来提示用户输入,包括密码字段的受保护文本等。
AHAlertView *alert = [[AHAlertView alloc] initWithTitle:@"Enter Password" message:@"[email protected]"];
alert.alertViewStyle = AHAlertViewStyleSecureTextInput;
[alert setCancelButtonTitle:@"Cancel" block:^{
NSLog(@"User canceled the alert instead of entering their password.");
}];
[alert addButtonWithTitle:@"OK" block:^{
NSLog(@"User entered the password: %@", [alert textFieldAtIndex:0].text);
}];
[alert show];
您可以使用传递给按钮标题的块执行任何操作,包括根据按下哪个按钮设置自定义消失动画
[alert setCancelButtonTitle:@"Cancel" block:^{
alert.dismissalStyle = AHAlertViewDismissalStyleTumble;
}];