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