@@ -181,6 +181,9 @@ + (void)initialize
181181 appearance.titleFont = [UIFont boldSystemFontOfSize: 20 ];
182182 appearance.messageFont = [UIFont systemFontOfSize: 16 ];
183183 appearance.buttonFont = [UIFont systemFontOfSize: [UIFont buttonFontSize ]];
184+ appearance.buttonColor = [UIColor colorWithWhite: 0.4 alpha: 1 ];
185+ appearance.cancelButtonColor = [UIColor colorWithWhite: 0.3 alpha: 1 ];
186+ appearance.destructiveButtonColor = [UIColor whiteColor ];
184187 appearance.cornerRadius = 2 ;
185188 appearance.shadowRadius = 8 ;
186189}
@@ -843,21 +846,21 @@ - (UIButton *)buttonForItemIndex:(NSUInteger)index
843846 case SIAlertViewButtonTypeCancel:
844847 normalImage = [UIImage imageNamed: @" SIAlertView.bundle/button-cancel" ];
845848 highlightedImage = [UIImage imageNamed: @" SIAlertView.bundle/button-cancel-d" ];
846- [button setTitleColor: [UIColor colorWithWhite: 0.3 alpha: 1 ] forState: UIControlStateNormal];
847- [button setTitleColor: [UIColor colorWithWhite: 0.3 alpha :0.8 ] forState: UIControlStateHighlighted];
849+ [button setTitleColor: self .cancelButtonColor forState: UIControlStateNormal];
850+ [button setTitleColor: [self .cancelButtonColor colorWithAlphaComponent :0.8 ] forState: UIControlStateHighlighted];
848851 break ;
849852 case SIAlertViewButtonTypeDestructive:
850853 normalImage = [UIImage imageNamed: @" SIAlertView.bundle/button-destructive" ];
851854 highlightedImage = [UIImage imageNamed: @" SIAlertView.bundle/button-destructive-d" ];
852- [button setTitleColor: [UIColor whiteColor ] forState: UIControlStateNormal];
853- [button setTitleColor: [UIColor colorWithWhite: 1 alpha :0.8 ] forState: UIControlStateHighlighted];
855+ [button setTitleColor: self .destructiveButtonColor forState: UIControlStateNormal];
856+ [button setTitleColor: [self .destructiveButtonColor colorWithAlphaComponent :0.8 ] forState: UIControlStateHighlighted];
854857 break ;
855858 case SIAlertViewButtonTypeDefault:
856859 default :
857860 normalImage = [UIImage imageNamed: @" SIAlertView.bundle/button-default" ];
858861 highlightedImage = [UIImage imageNamed: @" SIAlertView.bundle/button-default-d" ];
859- [button setTitleColor: [UIColor colorWithWhite: 0.4 alpha: 1 ] forState: UIControlStateNormal];
860- [button setTitleColor: [UIColor colorWithWhite: 0.4 alpha :0.8 ] forState: UIControlStateHighlighted];
862+ [button setTitleColor: self .buttonColor forState: UIControlStateNormal];
863+ [button setTitleColor: [self .buttonColor colorWithAlphaComponent :0.8 ] forState: UIControlStateHighlighted];
861864 break ;
862865 }
863866 CGFloat hInset = floorf (normalImage.size .width / 2 );
@@ -972,4 +975,41 @@ - (void)setShadowRadius:(CGFloat)shadowRadius
972975 self.containerView .layer .shadowRadius = shadowRadius;
973976}
974977
978+ - (void )setButtonColor : (UIColor *)buttonColor
979+ {
980+ if (_buttonColor == buttonColor) {
981+ return ;
982+ }
983+ _buttonColor = buttonColor;
984+ [self setColor: buttonColor toButtonsOfType: SIAlertViewButtonTypeDefault];
985+ }
986+
987+ - (void )setCancelButtonColor : (UIColor *)buttonColor
988+ {
989+ if (_cancelButtonColor == buttonColor) {
990+ return ;
991+ }
992+ _cancelButtonColor = buttonColor;
993+ [self setColor: buttonColor toButtonsOfType: SIAlertViewButtonTypeCancel];
994+ }
995+
996+ - (void )setDestructiveButtonColor : (UIColor *)buttonColor
997+ {
998+ if (_destructiveButtonColor == buttonColor) {
999+ return ;
1000+ }
1001+ _destructiveButtonColor = buttonColor;
1002+ [self setColor: buttonColor toButtonsOfType: SIAlertViewButtonTypeDestructive];
1003+ }
1004+
1005+ -(void )setColor : (UIColor *)color toButtonsOfType : (SIAlertViewButtonType)type {
1006+ for (NSUInteger i = 0 ; i < self.items .count ; i++) {
1007+ SIAlertItem *item = self.items [i];
1008+ if (item.type == type) {
1009+ UIButton *button = self.buttons [i];
1010+ [button setTitleColor: color forState: UIControlStateNormal];
1011+ }
1012+ }
1013+ }
1014+
9751015@end
0 commit comments