Skip to content

Commit 143da00

Browse files
committed
move default appearance to initialize method.
1 parent 2c758d6 commit 143da00

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

SIAlertView/SIAlertView.m

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ - (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+
}
176+
163177
- (id)init
164178
{
165179
return [self initWithTitle:nil andMessage:nil];
@@ -860,49 +874,46 @@ - (UIFont *)titleFont
860874
if (!_titleFont) {
861875
_titleFont = [[[self class] appearance] titleFont];
862876
}
863-
return _titleFont ? _titleFont : [UIFont boldSystemFontOfSize:20];
877+
return _titleFont;
864878
}
865879

866880
- (UIFont *)messageFont
867881
{
868882
if (!_messageFont) {
869883
_messageFont = [[[self class] appearance] messageFont];
870884
}
871-
return _messageFont ? _messageFont : [UIFont systemFontOfSize:16];
885+
return _messageFont;
872886
}
873887

874888
- (UIFont *)buttonFont
875889
{
876890
if (!_buttonFont) {
877891
_buttonFont = [[[self class] appearance] buttonFont];
878892
}
879-
return _buttonFont ? _buttonFont : [UIFont systemFontOfSize:[UIFont buttonFontSize]];
893+
return _buttonFont;
880894
}
881895

882896
- (UIColor *)titleColor
883897
{
884898
if(!_titleColor) {
885899
_titleColor = [[[self class] appearance] titleColor];
886900
}
887-
888-
return _titleColor ? _titleColor : [UIColor blackColor];
901+
return _titleColor;
889902
}
890903

891904
- (UIColor *)messageColor
892905
{
893906
if(!_messageColor) {
894907
_messageColor = [[[self class] appearance] messageColor];
895908
}
896-
897-
return _messageColor ? _messageColor : [UIColor darkGrayColor];
909+
return _messageColor;
898910
}
899911

900912
- (CGFloat)cornerRadius
901913
{
902914
if (_cornerRadius == 0) {
903915
_cornerRadius = [[[self class] appearance] cornerRadius];
904916
}
905-
906917
return _cornerRadius;
907918
}
908919

SIAlertViewExample/SIAlertViewExample/ViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ - (void)viewDidLoad
1919
{
2020
[super viewDidLoad];
2121

22+
// [[SIAlertView appearance] setTitleFont:[UIFont boldSystemFontOfSize:40]];
2223
[[SIAlertView appearance] setCornerRadius:4];
2324
}
2425

0 commit comments

Comments
 (0)