commit 91d51d07230e553e5f5dd3173a22eb75a88f2d2b Author: wu736139669 Date: Mon Jun 29 13:51:21 2015 +0800 first commit diff --git a/ASHUIAlertView.h b/ASHUIAlertView.h new file mode 100644 index 0000000..ab5d312 --- /dev/null +++ b/ASHUIAlertView.h @@ -0,0 +1,28 @@ +// +// ASHUIAlertView.h +// Ash_AWord +// +// Created by xmfish on 15/6/29. +// Copyright (c) 2015年 ash. All rights reserved. +// + +#import + +@interface ASHUIAlertView : UIAlertView +/** + * 弹出提示框 + * + * @param title <#title description#> + * @param message <#message description#> + * @param block <#block description#> + * @param cancelButtonTitle <#cancelButtonTitle description#> + * @param otherButtonTitles <#otherButtonTitles description#> + * + * @return <#return value description#> + */ ++ (id)showAlertWithTitle:(NSString *)title + message:(NSString *)message + completionBlock:(void (^)(NSUInteger buttonIndex, ASHUIAlertView *alertView))block + cancelButtonTitle:(NSString *)cancelButtonTitle + otherButtonTitles:(NSString *)otherButtonTitles, ...; +@end diff --git a/ASHUIAlertView.m b/ASHUIAlertView.m new file mode 100644 index 0000000..228d8b9 --- /dev/null +++ b/ASHUIAlertView.m @@ -0,0 +1,94 @@ +// +// ASHUIAlertView.m +// Ash_AWord +// +// Created by xmfish on 15/6/29. +// Copyright (c) 2015年 ash. All rights reserved. +// + +#import "ASHUIAlertView.h" +#import +@interface ASHUIAlertView () + +@end +@implementation ASHUIAlertView + + ++ (id)showAlertWithTitle:(NSString *)title message:(NSString *)message + completionBlock:(void (^)(NSUInteger buttonIndex, ASHUIAlertView *alertView))block + cancelButtonTitle:(NSString *)cancelButtonTitle + otherButtonTitles:(NSString *)otherButtonTitles, ... +{ + if (!cancelButtonTitle && !otherButtonTitles) { + return nil; + } + ASHUIAlertView *alertView = [[self alloc] initWithTitle:title + message:message + completionBlock:block + cancelButtonTitle:cancelButtonTitle + otherButtonTitles:nil]; + + if (otherButtonTitles != nil) { + id eachObject; + va_list argumentList; + if (otherButtonTitles) { + [alertView addButtonWithTitle:otherButtonTitles]; + va_start(argumentList, otherButtonTitles); + while ((eachObject = va_arg(argumentList, id))) { + [alertView addButtonWithTitle:eachObject]; + } + va_end(argumentList); + } + } + + [alertView show]; + + return alertView; + +} + + +- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex +{ + void (^block)(NSUInteger buttonIndex, UIAlertView *alertView) = objc_getAssociatedObject(self, "blockCallback"); + if (block) { + block(buttonIndex, self); + } +} + + +- (id)initWithTitle:(NSString *)title + message:(NSString *)message + completionBlock:(void (^)(NSUInteger buttonIndex, ASHUIAlertView *alertView))block + cancelButtonTitle:(NSString *)cancelButtonTitle + otherButtonTitles:(NSString *)otherButtonTitles, ... { + + objc_setAssociatedObject(self, "blockCallback", [block copy], OBJC_ASSOCIATION_RETAIN_NONATOMIC); + + if (self = [self initWithTitle:title + message:message + delegate:self + cancelButtonTitle:nil + otherButtonTitles:nil]) { + + if (cancelButtonTitle) { + [self addButtonWithTitle:cancelButtonTitle]; + self.cancelButtonIndex = [self numberOfButtons] - 1; + } + + id eachObject; + va_list argumentList; + if (otherButtonTitles) { + [self addButtonWithTitle:otherButtonTitles]; + va_start(argumentList, otherButtonTitles); + while ((eachObject = va_arg(argumentList, id))) { + [self addButtonWithTitle:eachObject]; + } + va_end(argumentList); + } + } + return self; +} + + +@end diff --git a/README.md b/README.md new file mode 100644 index 0000000..4e5e8f9 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# ASHUIAlertView \ No newline at end of file