mirror of
https://github.com/wu736139669/ASHUIAlertView.git
synced 2026-08-05 05:54:55 +00:00
first commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// ASHUIAlertView.h
|
||||
// Ash_AWord
|
||||
//
|
||||
// Created by xmfish on 15/6/29.
|
||||
// Copyright (c) 2015年 ash. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@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
|
||||
@@ -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 <objc/runtime.h>
|
||||
@interface ASHUIAlertView ()<UIAlertViewDelegate>
|
||||
|
||||
@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
|
||||
Reference in New Issue
Block a user