Skip to content

Commit

Permalink
add support for customize background color of alert view
Browse files Browse the repository at this point in the history
update example
  • Loading branch information
kyoji2 committed May 31, 2013
1 parent 44a5592 commit e927b2d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions SIAlertView/SIAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView);

@property (nonatomic, readonly, getter = isVisible) BOOL visible;

@property (nonatomic, strong) UIColor *viewBackgroundColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIColor *titleColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIColor *messageColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIFont *titleFont NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
Expand Down
10 changes: 10 additions & 0 deletions SIAlertView/SIAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ + (void)initialize
return;

SIAlertView *appearance = [self appearance];
appearance.viewBackgroundColor = [UIColor whiteColor];
appearance.titleColor = [UIColor blackColor];
appearance.messageColor = [UIColor darkGrayColor];
appearance.titleFont = [UIFont boldSystemFontOfSize:20];
Expand Down Expand Up @@ -883,6 +884,15 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag

#pragma mark - UIAppearance setters

- (void)setViewBackgroundColor:(UIColor *)viewBackgroundColor
{
if (_viewBackgroundColor == viewBackgroundColor) {
return;
}
_viewBackgroundColor = viewBackgroundColor;
self.containerView.backgroundColor = viewBackgroundColor;
}

- (void)setTitleFont:(UIFont *)titleFont
{
if (_titleFont == titleFont) {
Expand Down
6 changes: 5 additions & 1 deletion SIAlertViewExample/SIAlertViewExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "ViewController.h"
#import "SIAlertView.h"

#define TEST_UIAPPEARANCE 0

@interface ViewController ()

@end
Expand All @@ -18,12 +20,14 @@ @implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
#if TEST_UIAPPEARANCE
[[SIAlertView appearance] setMessageFont:[UIFont systemFontOfSize:13]];
[[SIAlertView appearance] setTitleColor:[UIColor greenColor]];
[[SIAlertView appearance] setMessageColor:[UIColor purpleColor]];
[[SIAlertView appearance] setCornerRadius:12];
[[SIAlertView appearance] setShadowRadius:20];
[[SIAlertView appearance] setViewBackgroundColor:[UIColor colorWithRed:0.891 green:0.936 blue:0.978 alpha:1.000]];
#endif
}

#pragma mark - Actions
Expand Down

0 comments on commit e927b2d

Please sign in to comment.