Skip to content

Commit 4ae22ca

Browse files
committed
enable custom appearance after showing
1 parent 143da00 commit 4ae22ca

2 files changed

Lines changed: 63 additions & 45 deletions

File tree

SIAlertView/SIAlertView.m

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -867,54 +867,64 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
867867
}
868868

869869

870-
#pragma mark - UIAppearance getters
870+
#pragma mark - UIAppearance setters
871871

872-
- (UIFont *)titleFont
872+
- (void)setTitleFont:(UIFont *)titleFont
873873
{
874-
if (!_titleFont) {
875-
_titleFont = [[[self class] appearance] titleFont];
874+
if (_titleFont == titleFont) {
875+
return;
876876
}
877-
return _titleFont;
877+
_titleFont = titleFont;
878+
self.titleLabel.font = titleFont;
879+
[self invaliadateLayout];
878880
}
879881

880-
- (UIFont *)messageFont
882+
- (void)setMessageFont:(UIFont *)messageFont
881883
{
882-
if (!_messageFont) {
883-
_messageFont = [[[self class] appearance] messageFont];
884+
if (_messageFont == messageFont) {
885+
return;
884886
}
885-
return _messageFont;
887+
_messageFont = messageFont;
888+
self.messageLabel.font = messageFont;
889+
[self invaliadateLayout];
886890
}
887891

888-
- (UIFont *)buttonFont
892+
- (void)setTitleColor:(UIColor *)titleColor
889893
{
890-
if (!_buttonFont) {
891-
_buttonFont = [[[self class] appearance] buttonFont];
894+
if (_titleColor == titleColor) {
895+
return;
892896
}
893-
return _buttonFont;
897+
_titleColor = titleColor;
898+
self.titleLabel.textColor = titleColor;
894899
}
895900

896-
- (UIColor *)titleColor
901+
- (void)setMessageColor:(UIColor *)messageColor
897902
{
898-
if(!_titleColor) {
899-
_titleColor = [[[self class] appearance] titleColor];
903+
if (_messageColor == messageColor) {
904+
return;
900905
}
901-
return _titleColor;
906+
_messageColor = messageColor;
907+
self.messageLabel.textColor = messageColor;
902908
}
903909

904-
- (UIColor *)messageColor
910+
- (void)setButtonFont:(UIFont *)buttonFont
905911
{
906-
if(!_messageColor) {
907-
_messageColor = [[[self class] appearance] messageColor];
912+
if (_buttonFont == buttonFont) {
913+
return;
914+
}
915+
_buttonFont = buttonFont;
916+
for (UIButton *button in self.buttons) {
917+
button.titleLabel.font = buttonFont;
908918
}
909-
return _messageColor;
910919
}
911920

912-
- (CGFloat)cornerRadius
921+
- (void)setCornerRadius:(CGFloat)cornerRadius
913922
{
914-
if (_cornerRadius == 0) {
915-
_cornerRadius = [[[self class] appearance] cornerRadius];
923+
if (_cornerRadius == cornerRadius) {
924+
return;
916925
}
917-
return _cornerRadius;
926+
_cornerRadius = cornerRadius;
927+
self.containerView.layer.cornerRadius = cornerRadius;
918928
}
919929

920930
@end

SIAlertViewExample/SIAlertViewExample/ViewController.m

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ - (void)viewDidLoad
1919
{
2020
[super viewDidLoad];
2121

22-
// [[SIAlertView appearance] setTitleFont:[UIFont boldSystemFontOfSize:40]];
23-
[[SIAlertView appearance] setCornerRadius:4];
22+
[[SIAlertView appearance] setMessageFont:[UIFont systemFontOfSize:13]];
23+
[[SIAlertView appearance] setTitleColor:[UIColor greenColor]];
24+
[[SIAlertView appearance] setMessageColor:[UIColor purpleColor]];
25+
[[SIAlertView appearance] setCornerRadius:12];
2426
}
2527

2628
#pragma mark - Actions
@@ -57,26 +59,32 @@ - (IBAction)alert1:(id)sender
5759
NSLog(@"%@, didDismissHandler", alertView);
5860
};
5961

62+
// alertView.cornerRadius = 4;
63+
// alertView.buttonFont = [UIFont boldSystemFontOfSize:12];
6064
[alertView show];
6165

62-
// alertView.title = @"3";
63-
// double delayInSeconds = 1.0;
64-
// dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
65-
// dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
66-
// alertView.title = @"2";
67-
// });
68-
// delayInSeconds = 2.0;
69-
// popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
70-
// dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
71-
// alertView.title = @"1";
72-
// });
73-
// delayInSeconds = 3.0;
74-
// popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
75-
// dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
76-
// NSLog(@"1=====");
77-
// [alertView dismissAnimated:YES];
78-
// NSLog(@"2=====");
79-
// });
66+
alertView.title = @"3";
67+
double delayInSeconds = 1.0;
68+
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
69+
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
70+
alertView.title = @"2";
71+
alertView.titleColor = [UIColor yellowColor];
72+
alertView.titleFont = [UIFont boldSystemFontOfSize:30];
73+
});
74+
delayInSeconds = 2.0;
75+
popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
76+
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
77+
alertView.title = @"1";
78+
alertView.titleColor = [UIColor greenColor];
79+
alertView.titleFont = [UIFont boldSystemFontOfSize:40];
80+
});
81+
delayInSeconds = 3.0;
82+
popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
83+
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
84+
NSLog(@"1=====");
85+
[alertView dismissAnimated:YES];
86+
NSLog(@"2=====");
87+
});
8088

8189
}
8290

0 commit comments

Comments
 (0)