diff --git a/Classes/PXAlertView+Customization.m b/Classes/PXAlertView+Customization.m index b2645d3..5ad2ff5 100644 --- a/Classes/PXAlertView+Customization.m +++ b/Classes/PXAlertView+Customization.m @@ -10,8 +10,11 @@ #import void * const kCancelBGKey = (void * const) &kCancelBGKey; +void * const kNonSelectedCancelBGKey = (void * const) &kNonSelectedCancelBGKey; void * const kOtherBGKey = (void * const) &kOtherBGKey; +void * const kNonSelectedOtherBGKey = (void * const) &kNonSelectedOtherBGKey; void * const kAllBGKey = (void * const) &kAllBGKey; +void * const kNonSelectedAllBGKey = (void * const) &kNonSelectedAllBGKey; @interface PXAlertView () @@ -89,11 +92,25 @@ - (void)setCustomBackgroundColorForButton:(id)sender } } +- (void)setNonSelectedCustomBackgroundColorForButton:(id)sender +{ + if (sender == self.cancelButton && [self nonSelectedCancelButtonBackgroundColor]) { + self.cancelButton.backgroundColor = [self nonSelectedCancelButtonBackgroundColor]; + } else if (sender == self.otherButton && [self nonSelectedOtherButtonBackgroundColor]) { + self.otherButton.backgroundColor = [self nonSelectedOtherButtonBackgroundColor]; + } else if ([self nonSelectedAllButtonsBackgroundColor]) { + [sender setBackgroundColor:[self nonSelectedAllButtonsBackgroundColor]]; + } else { + [sender setBackgroundColor:[UIColor clearColor]]; + } +} + - (void)setCancelButtonBackgroundColor:(UIColor *)color { objc_setAssociatedObject(self, kCancelBGKey, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC); [self.cancelButton addTarget:self action:@selector(setCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchDown]; [self.cancelButton addTarget:self action:@selector(setCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchDragEnter]; + [self.cancelButton addTarget:self action:@selector(setNonSelectedCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchDragExit]; } - (UIColor *)cancelButtonBackgroundColor @@ -103,9 +120,15 @@ - (UIColor *)cancelButtonBackgroundColor - (void)setCancelButtonNonSelectedBackgroundColor:(UIColor *)color { + objc_setAssociatedObject(self, kNonSelectedCancelBGKey, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.cancelButton.backgroundColor = color; } +- (UIColor *)nonSelectedCancelButtonBackgroundColor +{ + return objc_getAssociatedObject(self, kNonSelectedCancelBGKey); +} + - (void)setAllButtonsBackgroundColor:(UIColor *)color { objc_setAssociatedObject(self, kOtherBGKey, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC); @@ -114,6 +137,7 @@ - (void)setAllButtonsBackgroundColor:(UIColor *)color for (UIButton *button in self.buttons) { [button addTarget:self action:@selector(setCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchDown]; [button addTarget:self action:@selector(setCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchDragEnter]; + [button addTarget:self action:@selector(setNonSelectedCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchDragExit]; } } @@ -124,16 +148,27 @@ - (UIColor *)allButtonsBackgroundColor - (void)setAllButtonsNonSelectedBackgroundColor:(UIColor *)color { + objc_setAssociatedObject(self, kNonSelectedOtherBGKey, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + objc_setAssociatedObject(self, kNonSelectedCancelBGKey, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + objc_setAssociatedObject(self, kNonSelectedAllBGKey, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC); for (UIButton *button in self.buttons) { button.backgroundColor = color; } } +- (UIColor *)nonSelectedAllButtonsBackgroundColor +{ + return objc_getAssociatedObject(self, kNonSelectedAllBGKey); +} + - (void)setOtherButtonBackgroundColor:(UIColor *)color { objc_setAssociatedObject(self, kOtherBGKey, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC); [self.otherButton addTarget:self action:@selector(setCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchDown]; [self.otherButton addTarget:self action:@selector(setCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchDragEnter]; + [self.otherButton addTarget:self action:@selector(setNonSelectedCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchUpInside]; + [self.otherButton addTarget:self action:@selector(setNonSelectedCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchUpOutside]; + [self.otherButton addTarget:self action:@selector(setNonSelectedCustomBackgroundColorForButton:) forControlEvents:UIControlEventTouchDragExit]; } - (UIColor *)otherButtonBackgroundColor @@ -143,9 +178,15 @@ - (UIColor *)otherButtonBackgroundColor - (void)setOtherButtonNonSelectedBackgroundColor:(UIColor *)color { + objc_setAssociatedObject(self, kNonSelectedOtherBGKey, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.otherButton.backgroundColor = color; } +- (UIColor *)nonSelectedOtherButtonBackgroundColor +{ + return objc_getAssociatedObject(self, kNonSelectedOtherBGKey); +} + #pragma mark Buttons Text Colors - (void)setCancelButtonTextColor:(UIColor *)color { diff --git a/Classes/PXAlertView.m b/Classes/PXAlertView.m index 51e9ded..d58389a 100644 --- a/Classes/PXAlertView.m +++ b/Classes/PXAlertView.m @@ -311,6 +311,7 @@ - (UIButton *)genericButton [button setTitleColor:[UIColor colorWithWhite:0.25 alpha:1] forState:UIControlStateHighlighted]; [button addTarget:self action:@selector(dismiss:) forControlEvents:UIControlEventTouchUpInside]; [button addTarget:self action:@selector(setBackgroundColorForButton:) forControlEvents:UIControlEventTouchDown]; + [button addTarget:self action:@selector(setBackgroundColorForButton:) forControlEvents:UIControlEventTouchDragEnter]; [button addTarget:self action:@selector(clearBackgroundColorForButton:) forControlEvents:UIControlEventTouchDragExit]; return button; } diff --git a/PXAlertViewDemo/PXViewController.m b/PXAlertViewDemo/PXViewController.m index 416b9ee..6da434b 100755 --- a/PXAlertViewDemo/PXViewController.m +++ b/PXAlertViewDemo/PXViewController.m @@ -100,8 +100,17 @@ - (IBAction)showTwoButtonAlertView:(id)sender } }]; - [alert setCancelButtonBackgroundColor:[UIColor blueColor]]; - [alert setOtherButtonBackgroundColor:[UIColor redColor]]; + UIColor *blueNormal = [UIColor blueColor]; + UIColor *blueSelected = [UIColor colorWithRed:0.5 green:0.5 blue:1 alpha:1]; + [alert setCancelButtonNonSelectedBackgroundColor:blueNormal]; + [alert setCancelButtonBackgroundColor:blueSelected]; + + UIColor *redNormal = [UIColor redColor]; + UIColor *redSelected = [UIColor colorWithRed:1 green:0.5 blue:0.5 alpha:1]; + [alert setOtherButtonNonSelectedBackgroundColor:redNormal]; + [alert setOtherButtonBackgroundColor:redSelected]; + + [alert setAllButtonsTextColor:[UIColor whiteColor]]; } - (IBAction)showTwoStackedButtonAlertView:(id)sender @@ -119,8 +128,17 @@ - (IBAction)showTwoStackedButtonAlertView:(id)sender } }]; - [alert setCancelButtonBackgroundColor:[UIColor blueColor]]; - [alert setOtherButtonBackgroundColor:[UIColor redColor]]; + UIColor *blueNormal = [UIColor blueColor]; + UIColor *blueSelected = [UIColor colorWithRed:0.5 green:0.5 blue:1 alpha:1]; + [alert setCancelButtonNonSelectedBackgroundColor:blueNormal]; + [alert setCancelButtonBackgroundColor:blueSelected]; + + UIColor *redNormal = [UIColor redColor]; + UIColor *redSelected = [UIColor colorWithRed:1 green:0.5 blue:0.5 alpha:1]; + [alert setOtherButtonNonSelectedBackgroundColor:redNormal]; + [alert setOtherButtonBackgroundColor:redSelected]; + + [alert setAllButtonsTextColor:[UIColor whiteColor]]; } - (IBAction)showMultiButtonAlertView:(id)sender