Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Classes/PXAlertView+Customization.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#import <objc/runtime.h>

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 ()

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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];
}
}

Expand All @@ -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
Expand All @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions Classes/PXAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
26 changes: 22 additions & 4 deletions PXAlertViewDemo/PXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down