From 4aa3683c10877132beb71270e5111d522f893f27 Mon Sep 17 00:00:00 2001 From: Tatsuya Tanaka Date: Wed, 12 Aug 2015 02:21:21 +0900 Subject: [PATCH] Add ability to change background color of buttons --- SIAlertView/SIAlertView.h | 3 +++ SIAlertView/SIAlertView.m | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/SIAlertView/SIAlertView.h b/SIAlertView/SIAlertView.h index e4d620a..cb900b4 100644 --- a/SIAlertView/SIAlertView.h +++ b/SIAlertView/SIAlertView.h @@ -67,6 +67,9 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView); @property (nonatomic, strong) UIColor *buttonColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; @property (nonatomic, strong) UIColor *cancelButtonColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; @property (nonatomic, strong) UIColor *destructiveButtonColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; +@property (nonatomic, strong) UIColor *buttonBackgroundColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; +@property (nonatomic, strong) UIColor *cancelButtonBackgroundColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; +@property (nonatomic, strong) UIColor *destructiveButtonBackgroundColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; @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 diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 7a67df3..8b32f75 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -1135,6 +1135,32 @@ - (void)setDestructiveButtonColor:(UIColor *)buttonColor [self setColor:buttonColor toButtonsOfType:SIAlertViewButtonTypeDestructive]; } +- (void)setButtonBackgroundColor:(UIColor *)backgroundColor +{ + if (_buttonBackgroundColor == backgroundColor) { + return; + } + _buttonBackgroundColor = backgroundColor; + [self setBackgroundColor:backgroundColor toButtonsOfType:SIAlertViewButtonTypeDefault]; +} + +- (void)setCancelButtonBackgroundColor:(UIColor *)backgroundColor +{ + if (_cancelButtonBackgroundColor == backgroundColor) { + return; + } + _cancelButtonBackgroundColor = backgroundColor; + [self setBackgroundColor:backgroundColor toButtonsOfType:SIAlertViewButtonTypeCancel]; +} + +- (void)setDestructiveButtonBackgroundColor:(UIColor *)backgroundColor +{ + if (_destructiveButtonBackgroundColor == backgroundColor) { + return; + } + _destructiveButtonBackgroundColor = backgroundColor; + [self setBackgroundColor:backgroundColor toButtonsOfType:SIAlertViewButtonTypeDestructive]; +} - (void)setDefaultButtonImage:(UIImage *)defaultButtonImage forState:(UIControlState)state { @@ -1179,6 +1205,16 @@ -(void)setColor:(UIColor *)color toButtonsOfType:(SIAlertViewButtonType)type { } } +-(void)setBackgroundColor:(UIColor *)color toButtonsOfType:(SIAlertViewButtonType)type { + for (NSUInteger i = 0; i < self.items.count; i++) { + SIAlertItem *item = self.items[i]; + if(item.type == type) { + UIButton *button = self.buttons[i]; + button.backgroundColor = color; + } + } +} + # pragma mark - # pragma mark Enable parallax effect (iOS7 only)