In me the tiger sniffs the rose.
心有猛虎,细嗅蔷薇。
欢迎来到 我的博客: http://LeoDev.me
现在您可以使用 UIAlertView 结合 Block!
令人惊奇是吧!是的,所以现在就 star 这个项目吧!
LCAlertView 可在 CocoaPods 上使用。只需将以下内容添加到您的项目 Podfile 中
pod "LCAlertView-ObjC" # Podfile
通过包含以下导入使用:
#import "LCAlertView.h"
演示代码
// 1. Class method
LCAlertView *alertView = [LCAlertView title:@"LCAlertView" message:@"Quick Method" cancelButtonTitle:@"Cancel" otherButtonTitles:@[@"1", @"2"] clickedButtonAtIndex:^(LCAlertView *alertView, NSInteger buttonIndex) {
NSLog(@"clickedButtonAtIndex: %d", (int)buttonIndex);
}];
// 2. Instance method
LCAlertView *alertView = [[LCAlertView alloc] initWithTitle:@"LCAlertView" message:@"Quick Method" cancelButtonTitle:@"Cancel" otherButtonTitles:@[@"1", @"2", @"3"] clickedButtonAtIndex:^(LCAlertView *alertView, NSInteger buttonIndex) {
NSLog(@"clickedButtonAtIndex: %d", (int)buttonIndex);
}];
// show alertView
[alertView show];
您也可以使用属性
LCAlertView *alertView = [[LCAlertView alloc] initWithTitle:@"LCAlertView" message:@"Block Properties" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"1", @"2", @"3", nil];
alertView.clickedButtonAtIndexBlock = ^(LCAlertView *alertView, NSInteger buttonIndex) {
NSLog(@"clickedButtonAtIndex: %d", (int)buttonIndex);
};
alertView.cancelBlock = ^(LCAlertView *alertView) {
NSLog(@"cancel");
};
// You should set `willPresentAlertViewBlock` before `- (void)show;`
// 设置 willPresentAlertViewBlock 一定要放在 `- (void)show;`方法之前
alertView.willPresentAlertViewBlock = ^(LCAlertView *alertView) {
NSLog(@"willPresentAlertView");
};
alertView.didPresentAlertViewBlock = ^(LCAlertView *alertView) {
NSLog(@"didPresentAlertView");
};
alertView.willDismissWithButtonIndexBlock = ^(LCAlertView *alertView, NSInteger buttonIndex) {
NSLog(@"willDismissWithButtonIndexBlock: %d", (int)buttonIndex);
};
alertView.didDismissWithButtonIndexBlock = ^(LCAlertView *alertView, NSInteger buttonIndex) {
NSLog(@"didDismissWithButtonIndex: %d", (int)buttonIndex);
};
[alertView show];
如果您有任何问题,请提交一个 issue!谢谢!