diff --git a/ALAlertBanner/ALAlertBanner.h b/ALAlertBanner/ALAlertBanner.h index 5ac2e4b..61cdd4d 100755 --- a/ALAlertBanner/ALAlertBanner.h +++ b/ALAlertBanner/ALAlertBanner.h @@ -25,13 +25,6 @@ #import #import -typedef enum { - ALAlertBannerStyleSuccess = 0, - ALAlertBannerStyleFailure, - ALAlertBannerStyleNotify, - ALAlertBannerStyleWarning, -} ALAlertBannerStyle; - typedef enum { ALAlertBannerPositionTop = 0, ALAlertBannerPositionBottom, @@ -47,9 +40,11 @@ typedef enum { ALAlertBannerStateHidden } ALAlertBannerState; +@protocol ALBannerStyleConfigurationProtocol; + @interface ALAlertBanner : UIView -@property (nonatomic, readonly) ALAlertBannerStyle style; +@property (nonatomic, readonly) id styleConfiguration; @property (nonatomic, readonly) ALAlertBannerPosition position; @property (nonatomic, readonly) ALAlertBannerState state; @@ -88,19 +83,26 @@ typedef enum { */ @property (nonatomic) CGFloat bannerOpacity; +/** + Dissable default initializer. + + Use [ALAlertBanner alertBannerForView:styleConfiguration:position:title] and etc. + */ +- (instancetype)init NS_UNAVAILABLE; + /** The default methods to customize and display a banner. */ -+ (ALAlertBanner *)alertBannerForView:(UIView *)view style:(ALAlertBannerStyle)style position:(ALAlertBannerPosition)position title:(NSString *)title; ++ (ALAlertBanner *)alertBannerForView:(UIView *)view styleConfiguration:(id)styleConfiguration position:(ALAlertBannerPosition)position title:(NSString *)title; -+ (ALAlertBanner *)alertBannerForView:(UIView *)view style:(ALAlertBannerStyle)style position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle; ++ (ALAlertBanner *)alertBannerForView:(UIView *)view styleConfiguration:(id)styleConfiguration position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle; /** Optional method to handle a tap on a banner. By default, supplying a tap handler will disable allowTapToDismiss on this particular banner. If you want to reinstate this behavior alongside the tap handler, you can call `[[ALAlertBannerManager sharedManager] hideAlertBanner:alertBanner];` in tappedBlock(). */ -+ (ALAlertBanner *)alertBannerForView:(UIView *)view style:(ALAlertBannerStyle)style position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle tappedBlock:(void(^)(ALAlertBanner *alertBanner))tappedBlock; ++ (ALAlertBanner *)alertBannerForView:(UIView *)view styleConfiguration:(id)styleConfiguration position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle tappedBlock:(void(^)(ALAlertBanner *alertBanner))tappedBlock; /** Show the alert banner diff --git a/ALAlertBanner/ALAlertBanner.m b/ALAlertBanner/ALAlertBanner.m index c011d61..1016546 100755 --- a/ALAlertBanner/ALAlertBanner.m +++ b/ALAlertBanner/ALAlertBanner.m @@ -34,6 +34,7 @@ this software and associated documentation files (the "Software"), to deal in #import #import "ALAlertBanner+Private.h" #import "ALAlertBannerManager.h" +#import "ALBannerStyleConfiguration.h" static NSString * const kShowAlertBannerKey = @"showAlertBannerKey"; static NSString * const kHideAlertBannerKey = @"hideAlertBannerKey"; @@ -114,7 +115,6 @@ @interface ALAlertBanner () { ALAlertBannerManager *manager; } -@property (nonatomic, assign) ALAlertBannerStyle style; @property (nonatomic, assign) ALAlertBannerPosition position; @property (nonatomic, assign) ALAlertBannerState state; @property (nonatomic) NSTimeInterval fadeOutDuration; @@ -123,15 +123,16 @@ @interface ALAlertBanner () { @property (nonatomic, strong) UILabel *subtitleLabel; @property (nonatomic, strong) UIImageView *styleImageView; @property (nonatomic) CGRect parentFrameUponCreation; +@property (nonatomic, readwrite) id styleConfiguration; @end @implementation ALAlertBanner -- (id)init { +- (instancetype)init:(id)styleConfiguration { self = [super init]; if (self) { - + self.styleConfiguration = styleConfiguration; [self commonInit]; } @@ -172,26 +173,26 @@ - (void)setupSubviews { _titleLabel = [[UILabel alloc] init]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:13.f]; - _titleLabel.textColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + _titleLabel.textColor = self.styleConfiguration.titleTextColor; _titleLabel.textAlignment = NSTextAlignmentLeft; _titleLabel.numberOfLines = 1; _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail; _titleLabel.layer.shadowColor = [UIColor blackColor].CGColor; _titleLabel.layer.shadowOffset = CGSizeMake(0.f, -1.f); - _titleLabel.layer.shadowOpacity = 0.3f; + _titleLabel.layer.shadowOpacity = self.styleConfiguration.labelsShadowOpacity; _titleLabel.layer.shadowRadius = 0.f; [self addSubview:_titleLabel]; _subtitleLabel = [[UILabel alloc] init]; _subtitleLabel.backgroundColor = [UIColor clearColor]; _subtitleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:10.f]; - _subtitleLabel.textColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + _subtitleLabel.textColor = self.styleConfiguration.subtitleTextColor; _subtitleLabel.textAlignment = NSTextAlignmentLeft; _subtitleLabel.numberOfLines = 0; _subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping; _subtitleLabel.layer.shadowColor = [UIColor blackColor].CGColor; _subtitleLabel.layer.shadowOffset = CGSizeMake(0.f, -1.f); - _subtitleLabel.layer.shadowOpacity = 0.3f; + _subtitleLabel.layer.shadowOpacity = self.styleConfiguration.labelsShadowOpacity; _subtitleLabel.layer.shadowRadius = 0.f; [self addSubview:_subtitleLabel]; } @@ -199,31 +200,10 @@ - (void)setupSubviews { # pragma mark - # pragma mark Custom Setters & Getters --(void)setStyle:(ALAlertBannerStyle)style { - _style = style; +-(void)setStyleConfiguration:(id)styleConfiguration { + _styleConfiguration = styleConfiguration; - switch (style) { - case ALAlertBannerStyleSuccess: - self.styleImageView.image = [UIImage imageNamed:@"bannerSuccess.png"]; - break; - - case ALAlertBannerStyleFailure: - self.styleImageView.image = [UIImage imageNamed:@"bannerFailure.png"]; - break; - - case ALAlertBannerStyleNotify: - self.styleImageView.image = [UIImage imageNamed:@"bannerNotify.png"]; - break; - - case ALAlertBannerStyleWarning: - self.styleImageView.image = [UIImage imageNamed:@"bannerAlert.png"]; - - //tone the shadows down a little for the yellow background - self.titleLabel.layer.shadowOpacity = 0.2f; - self.subtitleLabel.layer.shadowOpacity = 0.2f; - - break; - } + self.styleImageView.image = self.styleConfiguration.image; } - (void)setShowShadow:(BOOL)showShadow { @@ -240,9 +220,7 @@ - (void)setShowShadow:(BOOL)showShadow { self.layer.shadowPath = [UIBezierPath bezierPathWithRect:shadowPath].CGPath; self.fadeInDuration = 0.15f; - } - - else { + } else { newShadowRadius = 0.f; self.layer.shadowRadius = 0.f; self.layer.shadowOffset = CGSizeZero; @@ -296,16 +274,16 @@ + (void)forceHideAllAlertBannersInView:(UIView *)view { [[ALAlertBannerManager sharedManager] forceHideAllAlertBannersInView:view]; } -+ (ALAlertBanner *)alertBannerForView:(UIView *)view style:(ALAlertBannerStyle)style position:(ALAlertBannerPosition)position title:(NSString *)title { - return [self alertBannerForView:view style:style position:position title:title subtitle:nil tappedBlock:nil]; ++ (ALAlertBanner *)alertBannerForView:(UIView *)view styleConfiguration:(id)styleConfiguration position:(ALAlertBannerPosition)position title:(NSString *)title { + return [self alertBannerForView:view styleConfiguration:styleConfiguration position:position title:title subtitle:nil tappedBlock:nil]; } -+ (ALAlertBanner *)alertBannerForView:(UIView *)view style:(ALAlertBannerStyle)style position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle { - return [self alertBannerForView:view style:style position:position title:title subtitle:subtitle tappedBlock:nil]; ++ (ALAlertBanner *)alertBannerForView:(UIView *)view styleConfiguration:(id)styleConfiguration position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle { + return [self alertBannerForView:view styleConfiguration:styleConfiguration position:position title:title subtitle:subtitle tappedBlock:nil]; } -+ (ALAlertBanner *)alertBannerForView:(UIView *)view style:(ALAlertBannerStyle)style position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle tappedBlock:(void (^)(ALAlertBanner *alertBanner))tappedBlock { - ALAlertBanner *alertBanner = [ALAlertBanner createAlertBannerForView:view style:style position:position title:title subtitle:subtitle]; ++ (ALAlertBanner *)alertBannerForView:(UIView *)view styleConfiguration:(id)styleConfiguration position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle tappedBlock:(void (^)(ALAlertBanner *alertBanner))tappedBlock { + ALAlertBanner *alertBanner = [ALAlertBanner createAlertBannerForView:view styleConfiguration:styleConfiguration position:position title:title subtitle:subtitle]; alertBanner.allowTapToDismiss = tappedBlock ? NO : alertBanner.allowTapToDismiss; alertBanner.tappedBlock = tappedBlock; return alertBanner; @@ -314,15 +292,14 @@ + (ALAlertBanner *)alertBannerForView:(UIView *)view style:(ALAlertBannerStyle)s # pragma mark - # pragma mark Internal Class Methods -+ (ALAlertBanner *)createAlertBannerForView:(UIView *)view style:(ALAlertBannerStyle)style position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle { - ALAlertBanner *alertBanner = [[ALAlertBanner alloc] init]; ++ (ALAlertBanner *)createAlertBannerForView:(UIView *)view styleConfiguration:(id)styleConfiguration position:(ALAlertBannerPosition)position title:(NSString *)title subtitle:(NSString *)subtitle { + ALAlertBanner *alertBanner = [[ALAlertBanner alloc] init:styleConfiguration]; if (![view isKindOfClass:[UIWindow class]] && position == ALAlertBannerPositionUnderNavBar) [[NSException exceptionWithName:@"Wrong ALAlertBannerPosition For View Type" reason:@"ALAlertBannerPositionUnderNavBar should only be used if you are presenting the alert banner on the AppDelegate window. Use ALAlertBannerPositionTop or ALAlertBannerPositionBottom for normal UIViews" userInfo:nil] raise]; alertBanner.titleLabel.text = !title ? @" " : title; alertBanner.subtitleLabel.text = subtitle; - alertBanner.style = style; alertBanner.position = position; alertBanner.state = ALAlertBannerStateHidden; @@ -696,21 +673,8 @@ - (void)updatePositionAfterRotationWithY:(CGFloat)yPos animated:(BOOL)animated { - (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 ALAlertBannerStyleWarning: - fillColor = [UIColor colorWithRed:(211/255.0) green:(209/255.0) blue:(100/255.0) alpha:1.f]; - break; - } + UIColor *fillColor; + fillColor = self.styleConfiguration.fillColor; NSArray *colorsArray = [NSArray arrayWithObjects:(id)[fillColor CGColor], (id)[[fillColor darkerColor] CGColor], nil]; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); @@ -740,21 +704,7 @@ - (id)nextAvailableViewController:(id)view { } - (NSString *)description { - NSString *styleString; - switch (self.style) { - case ALAlertBannerStyleSuccess: - styleString = @"ALAlertBannerStyleSuccess"; - break; - case ALAlertBannerStyleFailure: - styleString = @"ALAlertBannerStyleFailure"; - break; - case ALAlertBannerStyleNotify: - styleString = @"ALAlertBannerStyleNotify"; - break; - case ALAlertBannerStyleWarning: - styleString = @"ALAlertBannerStyleWarning"; - break; - } + NSString *styleString = self.styleConfiguration.styleString; NSString *positionString; switch (self.position) { case ALAlertBannerPositionTop: diff --git a/ALAlertBanner/ALBannerStyleConfiguration.h b/ALAlertBanner/ALBannerStyleConfiguration.h new file mode 100644 index 0000000..bc5bb9b --- /dev/null +++ b/ALAlertBanner/ALBannerStyleConfiguration.h @@ -0,0 +1,18 @@ + +#import + +@protocol ALBannerStyleConfigurationProtocol +@property (nonatomic, readonly) UIColor *fillColor; +@property (nonatomic, readonly) UIColor *titleTextColor; +@property (nonatomic, readonly) UIColor *subtitleTextColor; +@property (nonatomic, readonly) UIImage *image; +@property (nonatomic, readonly) CGFloat labelsShadowOpacity; +@property (nonatomic, readonly) NSString *styleString; +@end + +@interface ALBannerStyleConfiguration : NSObject ++ (ALBannerStyleConfiguration *)failureStyleConfiguration; ++ (ALBannerStyleConfiguration *)successStyleConfiguration; ++ (ALBannerStyleConfiguration *)notifyStyleConfiguration; ++ (ALBannerStyleConfiguration *)warningStyleConfiguration; +@end diff --git a/ALAlertBanner/ALBannerStyleConfiguration.m b/ALAlertBanner/ALBannerStyleConfiguration.m new file mode 100644 index 0000000..d828f89 --- /dev/null +++ b/ALAlertBanner/ALBannerStyleConfiguration.m @@ -0,0 +1,75 @@ + +#import "ALBannerStyleConfiguration.h" + +@interface ALBannerStyleConfiguration () +@property (nonatomic, strong) UIColor *fillColor; +@property (nonatomic, strong) UIColor *titleTextColor; +@property (nonatomic, strong) UIColor *subtitleTextColor; +@property (nonatomic, strong) UIImage *image; +@property (nonatomic, assign) CGFloat labelsShadowOpacity; +@property (nonatomic, strong) NSString *styleString; +@end + +@implementation ALBannerStyleConfiguration + ++ (ALBannerStyleConfiguration *)failureStyleConfiguration { + static ALBannerStyleConfiguration *failureConfiguration; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + failureConfiguration = [[ALBannerStyleConfiguration alloc] init]; + failureConfiguration.fillColor = [UIColor colorWithRed:(173/255.0) green:(48/255.0) blue:(48/255.0) alpha:1.f]; + failureConfiguration.titleTextColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + failureConfiguration.subtitleTextColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + failureConfiguration.image = [UIImage imageNamed:@"bannerFailure.png"]; + failureConfiguration.labelsShadowOpacity = 0.3; + failureConfiguration.styleString = @"ALAlertBannerStyleFailure"; + }); + return failureConfiguration; +} + ++ (ALBannerStyleConfiguration *)successStyleConfiguration { + static ALBannerStyleConfiguration *successConfiguration; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + successConfiguration = [[ALBannerStyleConfiguration alloc] init]; + successConfiguration.fillColor = [UIColor colorWithRed:(77/255.0) green:(175/255.0) blue:(67/255.0) alpha:1.f]; + successConfiguration.titleTextColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + successConfiguration.subtitleTextColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + successConfiguration.image = [UIImage imageNamed:@"bannerSuccess.png"]; + successConfiguration.labelsShadowOpacity = 0.3; + successConfiguration.styleString = @"ALAlertBannerStyleSuccess"; + }); + return successConfiguration; +} + ++ (ALBannerStyleConfiguration *)notifyStyleConfiguration { + static ALBannerStyleConfiguration *notifyConfiguration; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + notifyConfiguration = [[ALBannerStyleConfiguration alloc] init]; + notifyConfiguration.fillColor = [UIColor colorWithRed:(48/255.0) green:(110/255.0) blue:(173/255.0) alpha:1.f]; + notifyConfiguration.titleTextColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + notifyConfiguration.subtitleTextColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + notifyConfiguration.image = [UIImage imageNamed:@"bannerNotify.png"]; + notifyConfiguration.labelsShadowOpacity = 0.3; + notifyConfiguration.styleString = @"ALAlertBannerStyleNotify"; + }); + return notifyConfiguration; +} + ++ (ALBannerStyleConfiguration *)warningStyleConfiguration { + static ALBannerStyleConfiguration *warningConfiguration; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + warningConfiguration = [[ALBannerStyleConfiguration alloc] init]; + warningConfiguration.fillColor = [UIColor colorWithRed:(211/255.0) green:(209/255.0) blue:(100/255.0) alpha:1.f]; + warningConfiguration.titleTextColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + warningConfiguration.subtitleTextColor = [UIColor colorWithWhite:1.f alpha:0.9f]; + warningConfiguration.image = [UIImage imageNamed:@"bannerAlert.png"]; + warningConfiguration.labelsShadowOpacity = 0.2; + warningConfiguration.styleString = @"ALAlertBannerStyleWarning"; + }); + return warningConfiguration; +} + +@end diff --git a/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.pbxproj b/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.pbxproj index c58a0d6..29e2727 100644 --- a/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.pbxproj +++ b/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ 4FC799DF17BC33D0000AEC49 /* bannerNotify.png in Resources */ = {isa = PBXBuildFile; fileRef = 4FC799DB17BC33D0000AEC49 /* bannerNotify.png */; }; 4FC799E017BC33D0000AEC49 /* bannerSuccess.png in Resources */ = {isa = PBXBuildFile; fileRef = 4FC799DC17BC33D0000AEC49 /* bannerSuccess.png */; }; 4FFBA6F917BE970700C2A7F2 /* ALAlertBannerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4FFBA6F817BE970700C2A7F2 /* ALAlertBannerManager.m */; }; + D654E67B2077742100B8B286 /* ALBannerStyleConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = D654E67A2077742100B8B286 /* ALBannerStyleConfiguration.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -63,6 +64,8 @@ 4FC799DC17BC33D0000AEC49 /* bannerSuccess.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bannerSuccess.png; sourceTree = ""; }; 4FFBA6F717BE970700C2A7F2 /* ALAlertBannerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ALAlertBannerManager.h; sourceTree = ""; }; 4FFBA6F817BE970700C2A7F2 /* ALAlertBannerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ALAlertBannerManager.m; sourceTree = ""; }; + D654E6792077742100B8B286 /* ALBannerStyleConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ALBannerStyleConfiguration.h; sourceTree = ""; }; + D654E67A2077742100B8B286 /* ALBannerStyleConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ALBannerStyleConfiguration.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -140,6 +143,8 @@ 4FC799C617BC078A000AEC49 /* ALAlertBanner */ = { isa = PBXGroup; children = ( + D654E6792077742100B8B286 /* ALBannerStyleConfiguration.h */, + D654E67A2077742100B8B286 /* ALBannerStyleConfiguration.m */, 4FC799CA17BC078B000AEC49 /* ALAlertBanner.h */, 4FC799CB17BC078B000AEC49 /* ALAlertBanner.m */, 4FFBA6F717BE970700C2A7F2 /* ALAlertBannerManager.h */, @@ -243,6 +248,7 @@ 4FC799B317BC072A000AEC49 /* main.m in Sources */, 4FC799B717BC072A000AEC49 /* AppDelegate.m in Sources */, 4FC799C517BC0758000AEC49 /* ViewController.m in Sources */, + D654E67B2077742100B8B286 /* ALBannerStyleConfiguration.m in Sources */, 4FC799CD17BC078B000AEC49 /* ALAlertBanner.m in Sources */, 4FFBA6F917BE970700C2A7F2 /* ALAlertBannerManager.m in Sources */, ); diff --git a/ALAlertBannerDemo/ALAlertBannerDemo/TableViewController.m b/ALAlertBannerDemo/ALAlertBannerDemo/TableViewController.m index b50a2e8..73a44af 100644 --- a/ALAlertBannerDemo/ALAlertBannerDemo/TableViewController.m +++ b/ALAlertBannerDemo/ALAlertBannerDemo/TableViewController.m @@ -9,6 +9,7 @@ #import "TableViewController.h" #import "ALAlertBanner.h" #import "AppDelegate.h" +#import "ALBannerStyleConfiguration.h" @interface TableViewController () @@ -38,8 +39,25 @@ - (void)viewWillDisappear:(BOOL)animated { } - (void)showAlertBannerInView { - ALAlertBannerStyle randomStyle = (ALAlertBannerStyle)(arc4random_uniform(4)); - ALAlertBanner *banner = [ALAlertBanner alertBannerForView:self.view style:randomStyle position:ALAlertBannerPositionTop title:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit." subtitle:[AppDelegate randomLoremIpsum] tappedBlock:^(ALAlertBanner *alertBanner) { + NSInteger styleNumber = arc4random_uniform(4); + ALBannerStyleConfiguration *styleConfiguration = nil; + switch (styleNumber) { + case 0: + styleConfiguration = [ALBannerStyleConfiguration successStyleConfiguration]; + break; + case 1: + styleConfiguration = [ALBannerStyleConfiguration failureStyleConfiguration]; + break; + case 2: + styleConfiguration = [ALBannerStyleConfiguration notifyStyleConfiguration]; + break; + case 3: + styleConfiguration = [ALBannerStyleConfiguration warningStyleConfiguration]; + break; + default: + styleConfiguration = [ALBannerStyleConfiguration successStyleConfiguration]; + } + ALAlertBanner *banner = [ALAlertBanner alertBannerForView:self.view styleConfiguration:styleConfiguration position:ALAlertBannerPositionTop title:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit." subtitle:[AppDelegate randomLoremIpsum] tappedBlock:^(ALAlertBanner *alertBanner) { NSLog(@"tapped!"); [alertBanner hide]; }]; @@ -69,7 +87,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } - cell.textLabel.text = [NSString stringWithFormat:@"Cell %i", indexPath.row]; + cell.textLabel.text = [NSString stringWithFormat:@"Cell %li", (long)indexPath.row]; return cell; } diff --git a/ALAlertBannerDemo/ALAlertBannerDemo/ViewController.m b/ALAlertBannerDemo/ALAlertBannerDemo/ViewController.m index d6df6bd..06493b4 100755 --- a/ALAlertBannerDemo/ALAlertBannerDemo/ViewController.m +++ b/ALAlertBannerDemo/ALAlertBannerDemo/ViewController.m @@ -10,6 +10,7 @@ #import "ALAlertBanner.h" #import "AppDelegate.h" #import "TableViewController.h" +#import "ALBannerStyleConfiguration.h" @interface ViewController () @@ -123,10 +124,31 @@ - (void)configureView { self.animationDurationLabel.frame = CGRectMake(self.animationDurationSlider.frame.origin.x, self.animationDurationSlider.frame.origin.y + self.animationDurationSlider.frame.size.height, self.animationDurationSlider.frame.size.width, 20.f); } +- (ALBannerStyleConfiguration *)randomBannerStyleConfiguration { + NSInteger styleNumber = arc4random_uniform(4); + ALBannerStyleConfiguration *styleConfiguration = nil; + switch (styleNumber) { + case 0: + styleConfiguration = [ALBannerStyleConfiguration successStyleConfiguration]; + break; + case 1: + styleConfiguration = [ALBannerStyleConfiguration failureStyleConfiguration]; + break; + case 2: + styleConfiguration = [ALBannerStyleConfiguration notifyStyleConfiguration]; + break; + case 3: + styleConfiguration = [ALBannerStyleConfiguration warningStyleConfiguration]; + break; + default: + styleConfiguration = [ALBannerStyleConfiguration successStyleConfiguration]; + } + return styleConfiguration; +} + - (void)showAlertBannerInView:(UIButton *)button { ALAlertBannerPosition position = (ALAlertBannerPosition)button.tag; - ALAlertBannerStyle randomStyle = (ALAlertBannerStyle)(arc4random_uniform(4)); - ALAlertBanner *banner = [ALAlertBanner alertBannerForView:self.view style:randomStyle position:position title:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit." subtitle:[AppDelegate randomLoremIpsum] tappedBlock:^(ALAlertBanner *alertBanner) { + ALAlertBanner *banner = [ALAlertBanner alertBannerForView:self.view styleConfiguration:[self randomBannerStyleConfiguration] position:position title:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit." subtitle:[AppDelegate randomLoremIpsum] tappedBlock:^(ALAlertBanner *alertBanner) { NSLog(@"tapped!"); [alertBanner hide]; }]; @@ -138,9 +160,8 @@ - (void)showAlertBannerInView:(UIButton *)button { - (void)showAlertBannerInWindow:(UIButton *)button { AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; - ALAlertBannerStyle randomStyle = (ALAlertBannerStyle)(arc4random_uniform(4)); ALAlertBannerPosition position = (ALAlertBannerPosition)button.tag; - ALAlertBanner *banner = [ALAlertBanner alertBannerForView:appDelegate.window style:randomStyle position:position title:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit." subtitle:[AppDelegate randomLoremIpsum] tappedBlock:^(ALAlertBanner *alertBanner) { + ALAlertBanner *banner = [ALAlertBanner alertBannerForView:appDelegate.window styleConfiguration:[self randomBannerStyleConfiguration] position:position title:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit." subtitle:[AppDelegate randomLoremIpsum] tappedBlock:^(ALAlertBanner *alertBanner) { NSLog(@"tapped!"); [alertBanner hide]; }];