@@ -160,6 +160,21 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie
160160
161161@implementation SIAlertView
162162
163+ + (void )initialize
164+ {
165+ if (self != [SIAlertView class ])
166+ return ;
167+
168+ SIAlertView *appearance = [self appearance ];
169+ appearance.titleColor = [UIColor blackColor ];
170+ appearance.messageColor = [UIColor darkGrayColor ];
171+ appearance.titleFont = [UIFont boldSystemFontOfSize: 20 ];
172+ appearance.messageFont = [UIFont systemFontOfSize: 16 ];
173+ appearance.buttonFont = [UIFont systemFontOfSize: [UIFont buttonFontSize ]];
174+ appearance.cornerRadius = 2 ;
175+ appearance.shadowRadius = 8 ;
176+ }
177+
163178- (id )init
164179{
165180 return [self initWithTitle: nil andMessage: nil ];
@@ -725,7 +740,7 @@ - (void)setupContainerView
725740 self.containerView .backgroundColor = [UIColor whiteColor ];
726741 self.containerView .layer .cornerRadius = self.cornerRadius ;
727742 self.containerView .layer .shadowOffset = CGSizeZero;
728- self.containerView .layer .shadowRadius = 8 ;
743+ self.containerView .layer .shadowRadius = self. shadowRadius ;
729744 self.containerView .layer .shadowOpacity = 0.5 ;
730745 [self addSubview: self .containerView];
731746}
@@ -853,57 +868,73 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
853868}
854869
855870
856- #pragma mark - UIAppearance getters
871+ #pragma mark - UIAppearance setters
872+
873+ - (void )setTitleFont : (UIFont *)titleFont
874+ {
875+ if (_titleFont == titleFont) {
876+ return ;
877+ }
878+ _titleFont = titleFont;
879+ self.titleLabel .font = titleFont;
880+ [self invaliadateLayout ];
881+ }
857882
858- - (UIFont *)titleFont
883+ - (void ) setMessageFont : ( UIFont *)messageFont
859884{
860- if (!_titleFont ) {
861- _titleFont = [[[ self class ] appearance ] titleFont ] ;
885+ if (_messageFont == messageFont ) {
886+ return ;
862887 }
863- return _titleFont ? _titleFont : [UIFont boldSystemFontOfSize: 20 ];
888+ _messageFont = messageFont;
889+ self.messageLabel .font = messageFont;
890+ [self invaliadateLayout ];
864891}
865892
866- - (UIFont *)messageFont
893+ - (void ) setTitleColor : (UIColor *)titleColor
867894{
868- if (!_messageFont ) {
869- _messageFont = [[[ self class ] appearance ] messageFont ] ;
895+ if (_titleColor == titleColor ) {
896+ return ;
870897 }
871- return _messageFont ? _messageFont : [UIFont systemFontOfSize: 16 ];
898+ _titleColor = titleColor;
899+ self.titleLabel .textColor = titleColor;
872900}
873901
874- - (UIFont *)buttonFont
902+ - (void ) setMessageColor : (UIColor *)messageColor
875903{
876- if (!_buttonFont ) {
877- _buttonFont = [[[ self class ] appearance ] buttonFont ] ;
904+ if (_messageColor == messageColor ) {
905+ return ;
878906 }
879- return _buttonFont ? _buttonFont : [UIFont systemFontOfSize: [UIFont buttonFontSize ]];
907+ _messageColor = messageColor;
908+ self.messageLabel .textColor = messageColor;
880909}
881910
882- - (UIColor *)titleColor
911+ - (void ) setButtonFont : (UIFont *)buttonFont
883912{
884- if (!_titleColor) {
885- _titleColor = [[[self class ] appearance ] titleColor ];
913+ if (_buttonFont == buttonFont) {
914+ return ;
915+ }
916+ _buttonFont = buttonFont;
917+ for (UIButton *button in self.buttons ) {
918+ button.titleLabel .font = buttonFont;
886919 }
887-
888- return _titleColor ? _titleColor : [UIColor blackColor ];
889920}
890921
891- - (UIColor *) messageColor
922+ - (void ) setCornerRadius : (CGFloat) cornerRadius
892923{
893- if (!_messageColor ) {
894- _messageColor = [[[ self class ] appearance ] messageColor ] ;
924+ if (_cornerRadius == cornerRadius ) {
925+ return ;
895926 }
896-
897- return _messageColor ? _messageColor : [UIColor darkGrayColor ] ;
927+ _cornerRadius = cornerRadius;
928+ self. containerView . layer . cornerRadius = cornerRadius ;
898929}
899930
900- - (CGFloat)cornerRadius
931+ - (void ) setShadowRadius : ( CGFloat)shadowRadius
901932{
902- if (_cornerRadius == 0 ) {
903- _cornerRadius = [[[ self class ] appearance ] cornerRadius ] ;
933+ if (_shadowRadius == shadowRadius ) {
934+ return ;
904935 }
905-
906- return _cornerRadius ;
936+ _shadowRadius = shadowRadius;
937+ self. containerView . layer . shadowRadius = shadowRadius ;
907938}
908939
909940@end
0 commit comments