From e53e26bdb7f01ac2f0d0ff534ba513f5d0a84017 Mon Sep 17 00:00:00 2001 From: Lukasz Margielewski Date: Mon, 9 Sep 2013 12:57:38 +0200 Subject: [PATCH] Configurable colors --- ALAlertBanner/ALAlertBannerView.h | 4 +++ ALAlertBanner/ALAlertBannerView.m | 51 ++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/ALAlertBanner/ALAlertBannerView.h b/ALAlertBanner/ALAlertBannerView.h index f586db6..2c0c45b 100644 --- a/ALAlertBanner/ALAlertBannerView.h +++ b/ALAlertBanner/ALAlertBannerView.h @@ -112,4 +112,8 @@ typedef enum { -(void)updateSizeAndSubviewsAnimated:(BOOL)animated; -(void)updatePositionAfterRotationWithY:(CGFloat)yPos animated:(BOOL)animated; +#pragma mark - Configurable colors: + ++(void)setColor:(UIColor *)color forBannerStyle:(ALAlertBannerStyle)style; ++(UIColor *)colorFrBannerStyle:(ALAlertBannerStyle)style; @end diff --git a/ALAlertBanner/ALAlertBannerView.m b/ALAlertBanner/ALAlertBannerView.m index b9491fb..d43081e 100644 --- a/ALAlertBanner/ALAlertBannerView.m +++ b/ALAlertBanner/ALAlertBannerView.m @@ -633,21 +633,8 @@ -(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); - UIColor *fillColor; - switch (self.style) { - case ALAlertBannerStyleSuccess: - fillColor = [UIColor colorWithRed:(77/255.0) green:(175/255.0) blue:(67/255.0) alpha:1.f]; - break; - case ALAlertBannerStyleFailure: - fillColor = [UIColor colorWithRed:(173/255.0) green:(48/255.0) blue:(48/255.0) alpha:1.f]; - break; - case ALAlertBannerStyleNotify: - fillColor = [UIColor colorWithRed:(48/255.0) green:(110/255.0) blue:(173/255.0) alpha:1.f]; - break; - case ALAlertBannerStyleAlert: - fillColor = [UIColor colorWithRed:(211/255.0) green:(209/255.0) blue:(100/255.0) alpha:1.f]; - break; - } + UIColor *fillColor = [ALAlertBannerView colorFrBannerStyle:self.style]; + NSArray *colorsArray = [NSArray arrayWithObjects:(id)[fillColor CGColor], (id)[[fillColor darkerColor] CGColor], nil]; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); @@ -665,4 +652,38 @@ -(void)drawRect:(CGRect)rect CGContextFillRect(context, CGRectMake(0, 0, rect.size.width, 1.f)); } + +#pragma mark - Configurable colors: + ++(NSMutableDictionary *)colors{ + + static dispatch_once_t pred; + static NSMutableDictionary *shared = nil; + + dispatch_once(&pred, ^{ + shared = [[NSMutableDictionary alloc] initWithDictionary: + @{ + @(ALAlertBannerStyleSuccess) : [UIColor colorWithRed:(77/255.0) green:(175/255.0) blue:(67/255.0) alpha:1.f], + @(ALAlertBannerStyleFailure) : [UIColor colorWithRed:(173/255.0) green:(48/255.0) blue:(48/255.0) alpha:1.f], + @(ALAlertBannerStyleNotify) : [UIColor colorWithRed:(48/255.0) green:(110/255.0) blue:(173/255.0) alpha:1.f], + @(ALAlertBannerStyleAlert) : [UIColor colorWithRed:(211/255.0) green:(209/255.0) blue:(100/255.0) alpha:1.f], + }]; + + //[shared printEntityList]; + }); + return shared; +} ++(void)setColor:(UIColor *)color forBannerStyle:(ALAlertBannerStyle)style{ + + [[ALAlertBannerView colors] setObject:color forKey:@(style)]; + +} ++(UIColor *)colorFrBannerStyle:(ALAlertBannerStyle)style{ + + + UIColor *fillColor = [[ALAlertBannerView colors] objectForKey:@(style)]; + return fillColor; +} + + @end \ No newline at end of file