Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ALAlertBanner/ALAlertBanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "JALabel.h"

typedef enum {
ALAlertBannerStyleSuccess = 0,
ALAlertBannerStyleFailure,
ALAlertBannerStyleNotify,
ALAlertBannerStyleWarning,
ALAlertBannerStyleCustom,
} ALAlertBannerStyle;

typedef enum {
ALAlertBannerPositionTop = 0,
ALAlertBannerPositionBottom,
ALAlertBannerPositionUnderNavBar,

} ALAlertBannerPosition;

typedef enum {
Expand All @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions ALAlertBanner/ALAlertBanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
13 changes: 13 additions & 0 deletions ALAlertBanner/JALabel/JALabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// JALabel.h
// JALabel
//
// Created by Josh Adams on 5/1/13.
// Copyright (c) 2013 Josh Adams. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface JALabel : UILabel

@end
31 changes: 31 additions & 0 deletions ALAlertBanner/JALabel/JALabel.m
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions ALAlertBannerDemo/ALAlertBannerDemo.xcodeproj/project.pbxproj
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -63,6 +69,13 @@
4FC799DC17BC33D0000AEC49 /* bannerSuccess.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = bannerSuccess.png; sourceTree = "<group>"; };
4FFBA6F717BE970700C2A7F2 /* ALAlertBannerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ALAlertBannerManager.h; sourceTree = "<group>"; };
4FFBA6F817BE970700C2A7F2 /* ALAlertBannerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ALAlertBannerManager.m; sourceTree = "<group>"; };
5D24F4501859432E00821CAD /* JALabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JALabel.h; sourceTree = "<group>"; };
5D24F4511859432E00821CAD /* JALabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JALabel.m; sourceTree = "<group>"; };
5D24F4541859446800821CAD /* 1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 1.png; sourceTree = "<group>"; };
5D24F4551859446800821CAD /* 2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 2.png; sourceTree = "<group>"; };
5D24F4561859446800821CAD /* 3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 3.png; sourceTree = "<group>"; };
5D24F45A1859452100821CAD /* 4.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 4.png; sourceTree = "<group>"; };
5D24F45E1859475500821CAD /* 0.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 0.png; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -112,6 +125,7 @@
4FC799AC17BC072A000AEC49 /* ALAlertBannerDemo */ = {
isa = PBXGroup;
children = (
5D24F4531859446800821CAD /* images */,
4FC799B517BC072A000AEC49 /* AppDelegate.h */,
4FC799B617BC072A000AEC49 /* AppDelegate.m */,
4FC799C317BC0758000AEC49 /* ViewController.h */,
Expand Down Expand Up @@ -140,6 +154,7 @@
4FC799C617BC078A000AEC49 /* ALAlertBanner */ = {
isa = PBXGroup;
children = (
5D24F44F1859432E00821CAD /* JALabel */,
4FC799CA17BC078B000AEC49 /* ALAlertBanner.h */,
4FC799CB17BC078B000AEC49 /* ALAlertBanner.m */,
4FFBA6F717BE970700C2A7F2 /* ALAlertBannerManager.h */,
Expand All @@ -166,6 +181,27 @@
path = Images;
sourceTree = "<group>";
};
5D24F44F1859432E00821CAD /* JALabel */ = {
isa = PBXGroup;
children = (
5D24F4501859432E00821CAD /* JALabel.h */,
5D24F4511859432E00821CAD /* JALabel.m */,
);
path = JALabel;
sourceTree = "<group>";
};
5D24F4531859446800821CAD /* images */ = {
isa = PBXGroup;
children = (
5D24F45E1859475500821CAD /* 0.png */,
5D24F4541859446800821CAD /* 1.png */,
5D24F4551859446800821CAD /* 2.png */,
5D24F4561859446800821CAD /* 3.png */,
5D24F45A1859452100821CAD /* 4.png */,
);
path = images;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -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;
};
Expand All @@ -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 */,
Expand Down
Empty file.
26 changes: 22 additions & 4 deletions ALAlertBannerDemo/ALAlertBannerDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Binary file added ALAlertBannerDemo/ALAlertBannerDemo/images/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ALAlertBannerDemo/ALAlertBannerDemo/images/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ALAlertBannerDemo/ALAlertBannerDemo/images/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ALAlertBannerDemo/ALAlertBannerDemo/images/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ALAlertBannerDemo/ALAlertBannerDemo/images/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.