@@ -197,6 +197,9 @@ + (void)initialize
197197 appearance.titleFont = [UIFont boldSystemFontOfSize: 20 ];
198198 appearance.messageFont = [UIFont systemFontOfSize: 16 ];
199199 appearance.buttonFont = [UIFont systemFontOfSize: [UIFont buttonFontSize ]];
200+ appearance.buttonColor = [UIColor colorWithWhite: 0.4 alpha: 1 ];
201+ appearance.cancelButtonColor = [UIColor colorWithWhite: 0.3 alpha: 1 ];
202+ appearance.destructiveButtonColor = [UIColor whiteColor ];
200203 appearance.cornerRadius = 2 ;
201204 appearance.shadowRadius = 8 ;
202205}
@@ -865,21 +868,21 @@ - (UIButton *)buttonForItemIndex:(NSUInteger)index
865868 case SIAlertViewButtonTypeCancel:
866869 normalImage = [UIImage imageNamed: @" SIAlertView.bundle/button-cancel" ];
867870 highlightedImage = [UIImage imageNamed: @" SIAlertView.bundle/button-cancel-d" ];
868- [button setTitleColor: [UIColor colorWithWhite: 0.3 alpha: 1 ] forState: UIControlStateNormal];
869- [button setTitleColor: [UIColor colorWithWhite: 0.3 alpha :0.8 ] forState: UIControlStateHighlighted];
871+ [button setTitleColor: self .cancelButtonColor forState: UIControlStateNormal];
872+ [button setTitleColor: [self .cancelButtonColor colorWithAlphaComponent :0.8 ] forState: UIControlStateHighlighted];
870873 break ;
871874 case SIAlertViewButtonTypeDestructive:
872875 normalImage = [UIImage imageNamed: @" SIAlertView.bundle/button-destructive" ];
873876 highlightedImage = [UIImage imageNamed: @" SIAlertView.bundle/button-destructive-d" ];
874- [button setTitleColor: [UIColor whiteColor ] forState: UIControlStateNormal];
875- [button setTitleColor: [UIColor colorWithWhite: 1 alpha :0.8 ] forState: UIControlStateHighlighted];
877+ [button setTitleColor: self .destructiveButtonColor forState: UIControlStateNormal];
878+ [button setTitleColor: [self .destructiveButtonColor colorWithAlphaComponent :0.8 ] forState: UIControlStateHighlighted];
876879 break ;
877880 case SIAlertViewButtonTypeDefault:
878881 default :
879882 normalImage = [UIImage imageNamed: @" SIAlertView.bundle/button-default" ];
880883 highlightedImage = [UIImage imageNamed: @" SIAlertView.bundle/button-default-d" ];
881- [button setTitleColor: [UIColor colorWithWhite: 0.4 alpha: 1 ] forState: UIControlStateNormal];
882- [button setTitleColor: [UIColor colorWithWhite: 0.4 alpha :0.8 ] forState: UIControlStateHighlighted];
884+ [button setTitleColor: self .buttonColor forState: UIControlStateNormal];
885+ [button setTitleColor: [self .buttonColor colorWithAlphaComponent :0.8 ] forState: UIControlStateHighlighted];
883886 break ;
884887 }
885888 CGFloat hInset = floorf (normalImage.size .width / 2 );
@@ -994,4 +997,42 @@ - (void)setShadowRadius:(CGFloat)shadowRadius
994997 self.containerView .layer .shadowRadius = shadowRadius;
995998}
996999
1000+ - (void )setButtonColor : (UIColor *)buttonColor
1001+ {
1002+ if (_buttonColor == buttonColor) {
1003+ return ;
1004+ }
1005+ _buttonColor = buttonColor;
1006+ [self setColor: buttonColor toButtonsOfType: SIAlertViewButtonTypeDefault];
1007+ }
1008+
1009+ - (void )setCancelButtonColor : (UIColor *)buttonColor
1010+ {
1011+ if (_cancelButtonColor == buttonColor) {
1012+ return ;
1013+ }
1014+ _cancelButtonColor = buttonColor;
1015+ [self setColor: buttonColor toButtonsOfType: SIAlertViewButtonTypeCancel];
1016+ }
1017+
1018+ - (void )setDestructiveButtonColor : (UIColor *)buttonColor
1019+ {
1020+ if (_destructiveButtonColor == buttonColor) {
1021+ return ;
1022+ }
1023+ _destructiveButtonColor = buttonColor;
1024+ [self setColor: buttonColor toButtonsOfType: SIAlertViewButtonTypeDestructive];
1025+ }
1026+
1027+ -(void )setColor : (UIColor *)color toButtonsOfType : (SIAlertViewButtonType)type {
1028+ for (NSUInteger i = 0 ; i < self.items .count ; i++) {
1029+ SIAlertItem *item = self.items [i];
1030+ if (item.type == type) {
1031+ UIButton *button = self.buttons [i];
1032+ [button setTitleColor: color forState: UIControlStateNormal];
1033+ [button setTitleColor: [color colorWithAlphaComponent: 0.8 ] forState: UIControlStateHighlighted];
1034+ }
1035+ }
1036+ }
1037+
9971038@end
0 commit comments