diff --git a/ALAlertBanner/ALAlertBanner.h b/ALAlertBanner/ALAlertBanner.h index 5ac2e4b..9bf3c5e 100755 --- a/ALAlertBanner/ALAlertBanner.h +++ b/ALAlertBanner/ALAlertBanner.h @@ -24,18 +24,21 @@ #import #import +#import "JALabel.h" typedef enum { ALAlertBannerStyleSuccess = 0, ALAlertBannerStyleFailure, ALAlertBannerStyleNotify, ALAlertBannerStyleWarning, + ALAlertBannerStyleCustom, } ALAlertBannerStyle; typedef enum { ALAlertBannerPositionTop = 0, ALAlertBannerPositionBottom, ALAlertBannerPositionUnderNavBar, + } ALAlertBannerPosition; typedef enum { @@ -48,7 +51,9 @@ typedef enum { } ALAlertBannerState; @interface ALAlertBanner : UIView - +@property (nonatomic, strong) JALabel *titleLabel; +@property (nonatomic, strong) JALabel *subtitleLabel; +@property (nonatomic, strong) UIImageView *styleImageView; @property (nonatomic, readonly) ALAlertBannerStyle style; @property (nonatomic, readonly) ALAlertBannerPosition position; @property (nonatomic, readonly) ALAlertBannerState state; diff --git a/ALAlertBanner/ALAlertBanner.m b/ALAlertBanner/ALAlertBanner.m index 2ba1052..d5ff716 100755 --- a/ALAlertBanner/ALAlertBanner.m +++ b/ALAlertBanner/ALAlertBanner.m @@ -119,9 +119,6 @@ @interface ALAlertBanner () { @property (nonatomic, assign) ALAlertBannerState state; @property (nonatomic) NSTimeInterval fadeOutDuration; @property (nonatomic, readonly) BOOL isAnimating; -@property (nonatomic, strong) UILabel *titleLabel; -@property (nonatomic, strong) UILabel *subtitleLabel; -@property (nonatomic, strong) UIImageView *styleImageView; @property (nonatomic) CGRect parentFrameUponCreation; @end @@ -222,6 +219,14 @@ -(void)setStyle:(ALAlertBannerStyle)style { self.titleLabel.layer.shadowOpacity = 0.2f; self.subtitleLabel.layer.shadowOpacity = 0.2f; + case ALAlertBannerStyleCustom: + //self.styleImageView.image = [UIImage imageNamed:@"placeholder_notification"]; + + //tone the shadows down a little for the yellow background + self.titleLabel.layer.shadowOpacity = 0.2f; + self.subtitleLabel.layer.shadowOpacity = 0.2f; + + break; } } diff --git a/ALAlertBanner/JALabel/JALabel.h b/ALAlertBanner/JALabel/JALabel.h new file mode 100755 index 0000000..54d6cbd --- /dev/null +++ b/ALAlertBanner/JALabel/JALabel.h @@ -0,0 +1,13 @@ +// +// JALabel.h +// JALabel +// +// Created by Josh Adams on 5/1/13. +// Copyright (c) 2013 Josh Adams. All rights reserved. +// + +#import + +@interface JALabel : UILabel + +@end diff --git a/ALAlertBanner/JALabel/JALabel.m b/ALAlertBanner/JALabel/JALabel.m new file mode 100755 index 0000000..645d13d --- /dev/null +++ b/ALAlertBanner/JALabel/JALabel.m @@ -0,0 +1,31 @@ +// +// JALabel.m +// JALabel +// +// Created by Josh Adams on 5/1/13. +// Copyright (c) 2013 Josh Adams. All rights reserved. +// + +#import "JALabel.h" + +@implementation JALabel + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // Initialization code + } + return self; +} + +- (void)drawTextInRect:(CGRect)rect +{ + CGSize labelStringSize = [self.text sizeWithFont:self.font + constrainedToSize:CGSizeMake(self.frame.size.width, 9999) + lineBreakMode:self.lineBreakMode]; + + [super drawTextInRect:CGRectMake(0, 0, self.frame.size.width, labelStringSize.height)]; +} + +@end diff --git a/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.pbxproj b/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index c58a0d6..449bfb1 --- a/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.pbxproj +++ b/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.pbxproj @@ -29,6 +29,12 @@ 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 */; }; + 5D24F4521859432E00821CAD /* JALabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D24F4511859432E00821CAD /* JALabel.m */; }; + 5D24F4571859446800821CAD /* 1.png in Resources */ = {isa = PBXBuildFile; fileRef = 5D24F4541859446800821CAD /* 1.png */; }; + 5D24F4581859446800821CAD /* 2.png in Resources */ = {isa = PBXBuildFile; fileRef = 5D24F4551859446800821CAD /* 2.png */; }; + 5D24F4591859446800821CAD /* 3.png in Resources */ = {isa = PBXBuildFile; fileRef = 5D24F4561859446800821CAD /* 3.png */; }; + 5D24F45C1859452100821CAD /* 4.png in Resources */ = {isa = PBXBuildFile; fileRef = 5D24F45A1859452100821CAD /* 4.png */; }; + 5D24F45F1859475500821CAD /* 0.png in Resources */ = {isa = PBXBuildFile; fileRef = 5D24F45E1859475500821CAD /* 0.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -63,6 +69,13 @@ 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 = ""; }; + 5D24F4501859432E00821CAD /* JALabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JALabel.h; sourceTree = ""; }; + 5D24F4511859432E00821CAD /* JALabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JALabel.m; sourceTree = ""; }; + 5D24F4541859446800821CAD /* 1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 1.png; sourceTree = ""; }; + 5D24F4551859446800821CAD /* 2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 2.png; sourceTree = ""; }; + 5D24F4561859446800821CAD /* 3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 3.png; sourceTree = ""; }; + 5D24F45A1859452100821CAD /* 4.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 4.png; sourceTree = ""; }; + 5D24F45E1859475500821CAD /* 0.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 0.png; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -112,6 +125,7 @@ 4FC799AC17BC072A000AEC49 /* ALAlertBannerDemo */ = { isa = PBXGroup; children = ( + 5D24F4531859446800821CAD /* images */, 4FC799B517BC072A000AEC49 /* AppDelegate.h */, 4FC799B617BC072A000AEC49 /* AppDelegate.m */, 4FC799C317BC0758000AEC49 /* ViewController.h */, @@ -140,6 +154,7 @@ 4FC799C617BC078A000AEC49 /* ALAlertBanner */ = { isa = PBXGroup; children = ( + 5D24F44F1859432E00821CAD /* JALabel */, 4FC799CA17BC078B000AEC49 /* ALAlertBanner.h */, 4FC799CB17BC078B000AEC49 /* ALAlertBanner.m */, 4FFBA6F717BE970700C2A7F2 /* ALAlertBannerManager.h */, @@ -166,6 +181,27 @@ path = Images; sourceTree = ""; }; + 5D24F44F1859432E00821CAD /* JALabel */ = { + isa = PBXGroup; + children = ( + 5D24F4501859432E00821CAD /* JALabel.h */, + 5D24F4511859432E00821CAD /* JALabel.m */, + ); + path = JALabel; + sourceTree = ""; + }; + 5D24F4531859446800821CAD /* images */ = { + isa = PBXGroup; + children = ( + 5D24F45E1859475500821CAD /* 0.png */, + 5D24F4541859446800821CAD /* 1.png */, + 5D24F4551859446800821CAD /* 2.png */, + 5D24F4561859446800821CAD /* 3.png */, + 5D24F45A1859452100821CAD /* 4.png */, + ); + path = images; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -227,8 +263,13 @@ 4FC799D617BC07B7000AEC49 /* bannerSuccess@2x.png in Resources */, 4FC799DD17BC33D0000AEC49 /* bannerAlert.png in Resources */, 4FC799DE17BC33D0000AEC49 /* bannerFailure.png in Resources */, + 5D24F4591859446800821CAD /* 3.png in Resources */, + 5D24F45F1859475500821CAD /* 0.png in Resources */, 4FC799DF17BC33D0000AEC49 /* bannerNotify.png in Resources */, + 5D24F45C1859452100821CAD /* 4.png in Resources */, + 5D24F4581859446800821CAD /* 2.png in Resources */, 4FC799E017BC33D0000AEC49 /* bannerSuccess.png in Resources */, + 5D24F4571859446800821CAD /* 1.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -240,6 +281,7 @@ buildActionMask = 2147483647; files = ( 203ADC231809F1B9001E4C68 /* TableViewController.m in Sources */, + 5D24F4521859432E00821CAD /* JALabel.m in Sources */, 4FC799B317BC072A000AEC49 /* main.m in Sources */, 4FC799B717BC072A000AEC49 /* AppDelegate.m in Sources */, 4FC799C517BC0758000AEC49 /* ViewController.m in Sources */, diff --git a/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/ALAlertBannerDemo/ALAlertBannerDemo/ViewController.m b/ALAlertBannerDemo/ALAlertBannerDemo/ViewController.m index d6df6bd..031b063 100755 --- a/ALAlertBannerDemo/ALAlertBannerDemo/ViewController.m +++ b/ALAlertBannerDemo/ALAlertBannerDemo/ViewController.m @@ -65,7 +65,7 @@ - (void)viewDidLoad { self.underNavButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; self.underNavButton.tag = ALAlertBannerPositionUnderNavBar; - [self.underNavButton setTitle:@"UIWindow" forState:UIControlStateNormal]; + [self.underNavButton setTitle:@"Custom" forState:UIControlStateNormal]; [self.underNavButton addTarget:self action:@selector(showAlertBannerInWindow:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.underNavButton]; @@ -115,7 +115,7 @@ - (void)viewWillDisappear:(BOOL)animated { - (void)configureView { self.topButton.frame = CGRectMake(20, self.view.frame.size.height/2 - 80.f, (self.view.frame.size.width - 40.f)/3, 40.f); self.bottomButton.frame = CGRectMake(self.topButton.frame.origin.x + self.topButton.frame.size.width, self.topButton.frame.origin.y, self.topButton.frame.size.width, self.topButton.frame.size.height); - self.underNavButton.frame = CGRectMake(self.bottomButton.frame.origin.x + self.bottomButton.frame.size.width, self.topButton.frame.origin.y, self.topButton.frame.size.width, self.topButton.frame.size.height); + self.underNavButton.frame = CGRectMake(0, self.view.bounds.size.height - 44, self.topButton.frame.size.width, self.topButton.frame.size.height); self.secondsToShowSlider.frame = CGRectMake(self.topButton.frame.origin.x, self.topButton.frame.origin.y + self.topButton.frame.size.height + 20.f, self.view.frame.size.width - 40.f, 20.f); self.secondsToShowLabel.frame = CGRectMake(self.secondsToShowSlider.frame.origin.x, self.secondsToShowSlider.frame.origin.y + self.secondsToShowSlider.frame.size.height, self.secondsToShowSlider.frame.size.width, 20.f); @@ -126,10 +126,13 @@ - (void)configureView { - (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 style:randomStyle position:position title:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit." subtitle:[AppDelegate randomLoremIpsum] tappedBlock:^(ALAlertBanner *alertBanner) { NSLog(@"tapped!"); [alertBanner hide]; }]; + + banner.secondsToShow = self.secondsToShow; banner.showAnimationDuration = self.showAnimationDuration; banner.hideAnimationDuration = self.hideAnimationDuration; @@ -138,12 +141,27 @@ - (void)showAlertBannerInView:(UIButton *)button { - (void)showAlertBannerInWindow:(UIButton *)button { AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; - ALAlertBannerStyle randomStyle = (ALAlertBannerStyle)(arc4random_uniform(4)); + ALAlertBannerStyle randomStyle = ALAlertBannerStyleCustom;//(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) { NSLog(@"tapped!"); [alertBanner hide]; }]; + + if (randomStyle == ALAlertBannerStyleCustom) { + banner.frame =CGRectMake(0, 0, 320, 100); + banner.backgroundColor = [UIColor colorWithRed:0.933 green:0.922 blue:0.941 alpha:1.000]; + banner.styleImageView.frame = CGRectMake(0, 0, 100, 95); + int randomImage = (int)(arc4random_uniform(4)); + banner.styleImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",randomImage]]; + NSLog(@"randomImage:%d",randomImage); + banner.titleLabel.frame =CGRectMake(100, 0, 200, 20); + banner.titleLabel.textColor = [UIColor colorWithRed:0.231 green:0.231 blue:0.235 alpha:1.000]; + banner.subtitleLabel.frame =CGRectMake(100, 0, 200, 100); + banner.subtitleLabel.textColor = [UIColor colorWithRed:0.231 green:0.231 blue:0.235 alpha:1.000]; + } + + banner.secondsToShow = self.secondsToShow; banner.showAnimationDuration = self.showAnimationDuration; banner.hideAnimationDuration = self.hideAnimationDuration; diff --git a/ALAlertBannerDemo/ALAlertBannerDemo/images/0.png b/ALAlertBannerDemo/ALAlertBannerDemo/images/0.png new file mode 100644 index 0000000..a3e70f8 Binary files /dev/null and b/ALAlertBannerDemo/ALAlertBannerDemo/images/0.png differ diff --git a/ALAlertBannerDemo/ALAlertBannerDemo/images/1.png b/ALAlertBannerDemo/ALAlertBannerDemo/images/1.png new file mode 100644 index 0000000..315e744 Binary files /dev/null and b/ALAlertBannerDemo/ALAlertBannerDemo/images/1.png differ diff --git a/ALAlertBannerDemo/ALAlertBannerDemo/images/2.png b/ALAlertBannerDemo/ALAlertBannerDemo/images/2.png new file mode 100644 index 0000000..79c0b4d Binary files /dev/null and b/ALAlertBannerDemo/ALAlertBannerDemo/images/2.png differ diff --git a/ALAlertBannerDemo/ALAlertBannerDemo/images/3.png b/ALAlertBannerDemo/ALAlertBannerDemo/images/3.png new file mode 100644 index 0000000..721797f Binary files /dev/null and b/ALAlertBannerDemo/ALAlertBannerDemo/images/3.png differ diff --git a/ALAlertBannerDemo/ALAlertBannerDemo/images/4.png b/ALAlertBannerDemo/ALAlertBannerDemo/images/4.png new file mode 100644 index 0000000..804869e Binary files /dev/null and b/ALAlertBannerDemo/ALAlertBannerDemo/images/4.png differ