From 6f69bc9fa1e3a0fde7235aa9b40d560a856458aa Mon Sep 17 00:00:00 2001 From: Gabriel Lim Date: Tue, 3 Sep 2013 15:08:22 +0800 Subject: [PATCH] Added convenience method to quickly open an alert view with dismiss button --- SIAlertView/SIAlertView.h | 2 ++ SIAlertView/SIAlertView.m | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/SIAlertView/SIAlertView.h b/SIAlertView/SIAlertView.h index 156c676..16a899c 100644 --- a/SIAlertView/SIAlertView.h +++ b/SIAlertView/SIAlertView.h @@ -62,6 +62,8 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView); @property (nonatomic, assign) CGFloat cornerRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 2.0 @property (nonatomic, assign) CGFloat shadowRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 8.0 ++ (void)showMessage:(NSString *)message withDismissButtonText:(NSString *)buttonText andOptionalTransitionType:(SIAlertViewTransitionStyle)transitionStyle; // Convenience method + - (void)setDefaultButtonImage:(UIImage *)defaultButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; - (void)setCancelButtonImage:(UIImage *)cancelButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; - (void)setDestructiveButtonImage:(UIImage *)destructiveButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 7895934..7e05e22 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -79,6 +79,22 @@ @interface SIAlertBackgroundWindow () @implementation SIAlertBackgroundWindow +#pragma mark - Convenience method ++ (void)showMessage:(NSString *)message withTitle:(NSString *)title withDismissButtonText:(NSString *)buttonText andOptionalTransitionType:(SIAlertViewTransitionStyle)transitionStyle { + + SIAlertView *alertView = [self initWithTitle:title andMessage:message]; + + if (transitionStyle) { + alertView.transitionStyle = transitionStyle; + } + + [alertView addButtonWithTitle:buttonText type:SIAlertViewButtonTypeCancel handler:^(SIAlertView *alertView) { + // Nothing + }]; + [alertView show]; +} + + - (id)initWithFrame:(CGRect)frame andStyle:(SIAlertViewBackgroundStyle)style { self = [super initWithFrame:frame];