Skip to content

Commit e927b2d

Browse files
committed
add support for customize background color of alert view
update example
1 parent 44a5592 commit e927b2d

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

SIAlertView/SIAlertView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView);
5050

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

53+
@property (nonatomic, strong) UIColor *viewBackgroundColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
5354
@property (nonatomic, strong) UIColor *titleColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
5455
@property (nonatomic, strong) UIColor *messageColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
5556
@property (nonatomic, strong) UIFont *titleFont NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

SIAlertView/SIAlertView.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ + (void)initialize
172172
return;
173173

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

884885
#pragma mark - UIAppearance setters
885886

887+
- (void)setViewBackgroundColor:(UIColor *)viewBackgroundColor
888+
{
889+
if (_viewBackgroundColor == viewBackgroundColor) {
890+
return;
891+
}
892+
_viewBackgroundColor = viewBackgroundColor;
893+
self.containerView.backgroundColor = viewBackgroundColor;
894+
}
895+
886896
- (void)setTitleFont:(UIFont *)titleFont
887897
{
888898
if (_titleFont == titleFont) {

SIAlertViewExample/SIAlertViewExample/ViewController.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#import "ViewController.h"
1010
#import "SIAlertView.h"
1111

12+
#define TEST_UIAPPEARANCE 0
13+
1214
@interface ViewController ()
1315

1416
@end
@@ -18,12 +20,14 @@ @implementation ViewController
1820
- (void)viewDidLoad
1921
{
2022
[super viewDidLoad];
21-
23+
#if TEST_UIAPPEARANCE
2224
[[SIAlertView appearance] setMessageFont:[UIFont systemFontOfSize:13]];
2325
[[SIAlertView appearance] setTitleColor:[UIColor greenColor]];
2426
[[SIAlertView appearance] setMessageColor:[UIColor purpleColor]];
2527
[[SIAlertView appearance] setCornerRadius:12];
2628
[[SIAlertView appearance] setShadowRadius:20];
29+
[[SIAlertView appearance] setViewBackgroundColor:[UIColor colorWithRed:0.891 green:0.936 blue:0.978 alpha:1.000]];
30+
#endif
2731
}
2832

2933
#pragma mark - Actions

0 commit comments

Comments
 (0)