Skip to content

Commit 88ba364

Browse files
committed
Merge branch 'feature/uiappearence' into develop
2 parents 2c758d6 + 932c553 commit 88ba364

3 files changed

Lines changed: 91 additions & 49 deletions

File tree

SIAlertView/SIAlertView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView);
5050
@property (nonatomic, strong) UIFont *titleFont NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
5151
@property (nonatomic, strong) UIFont *messageFont NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
5252
@property (nonatomic, strong) UIFont *buttonFont NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
53-
@property (nonatomic, assign) CGFloat cornerRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
53+
@property (nonatomic, assign) CGFloat cornerRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 2.0
54+
@property (nonatomic, assign) CGFloat shadowRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 8.0
5455

5556
- (id)initWithTitle:(NSString *)title andMessage:(NSString *)message;
5657
- (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type handler:(SIAlertViewHandler)handler;

SIAlertView/SIAlertView.m

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

SIAlertViewExample/SIAlertViewExample/ViewController.m

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

22-
[[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];
26+
[[SIAlertView appearance] setShadowRadius:20];
2327
}
2428

2529
#pragma mark - Actions
@@ -56,26 +60,32 @@ - (IBAction)alert1:(id)sender
5660
NSLog(@"%@, didDismissHandler", alertView);
5761
};
5862

63+
// alertView.cornerRadius = 4;
64+
// alertView.buttonFont = [UIFont boldSystemFontOfSize:12];
5965
[alertView show];
6066

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

8090
}
8191

0 commit comments

Comments
 (0)