Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added completion block execution #75

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
24fa8d3
Added completion block execution
pventura1976 Mar 10, 2015
a4542d0
Missing completion block
pventura1976 Mar 11, 2015
7e705d4
Project recommended settings
pventura1976 Mar 11, 2015
fdf83b3
Update BlockAlertView.m
taymer Apr 8, 2015
44a7b8f
Update BlockAlertView.h
taymer Apr 8, 2015
425cccf
Update BlockAlertsAnd-ActionSheets.podspec
taymer Apr 8, 2015
d5231ce
Update BlockAlertsAnd-ActionSheets.podspec
taymer Apr 8, 2015
39cf8c5
Update BlockAlertsAnd-ActionSheets.podspec
taymer Apr 8, 2015
5e7e1b7
Update BlockAlertView.h
taymer Apr 8, 2015
27f26d8
Update BlockAlertView.m
taymer Apr 8, 2015
9608b80
Update BlockAlertView.h
taymer May 5, 2015
4903a37
Update BlockAlertView.m
taymer May 5, 2015
e32e3b1
Update BlockBackground.m
taymer May 5, 2015
6b407a8
Update BlockAlertsAnd-ActionSheets.podspec
taymer May 5, 2015
ed79186
Update BlockBackground.m
taymer May 7, 2015
e95dd0b
Orientation issue on ios8
taymer May 7, 2015
4a7608c
Update BlockAlertsAnd-ActionSheets.podspec
taymer May 7, 2015
2a2ef3f
Added all in one line buttons and modified colors
taymer May 7, 2015
2fc310e
Added all in one line buttons and modified colors
taymer May 7, 2015
1dac714
Added all in one line buttons and modified colors
taymer May 7, 2015
d8c0492
Added all in one line buttons and modified colors
taymer May 7, 2015
ccbfd64
No Requires ARC
pventura1976 May 11, 2015
a9b5205
new file: alert-blue-button.png
May 29, 2015
347092e
version increment
May 29, 2015
0ee799d
Changed blue tone
May 29, 2015
72f7806
Added blue color for actionsheet
May 29, 2015
770221e
Colored actionbutton
May 29, 2015
4da5ac2
Update BlockAlertView.h
taymer Feb 18, 2016
1a0d3de
Update BlockAlertView.m
taymer Feb 18, 2016
1113011
Update BlockAlertsAnd-ActionSheets.podspec
taymer Nov 9, 2016
3d1fffb
Merge remote-tracking branch 'gpambrozio/master'
pventura1976 Dec 13, 2016
f87ce08
Merge taymer and pventura1976 forks
pventura1976 Dec 16, 2016
d8ead6b
Merges adjustments
pventura1976 Dec 16, 2016
8ffb45f
Update version, homepage, author and source properties
pventura1976 Dec 16, 2016
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
12 changes: 6 additions & 6 deletions BlockAlertsAnd-ActionSheets.podspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Pod::Spec.new do |s|
s.name = "BlockAlertsAnd-ActionSheets"
s.version = "1.0.6"
s.version = "1.0.11"
s.summary = 'Beautifully done UIAlertView and UIActionSheet replacements inspired by TweetBot.'
s.homepage = "https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets"
s.homepage = "https://github.com/pventura1976/BlockAlertsAnd-ActionSheets"
s.license = 'MIT'
s.author = { 'Gustavo Ambrozio' => '', "Barrett Jacobsen" => "[email protected]", "Jose Santiago Jr" => '' }
s.source = { :git => 'https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets.git', :tag => "#{s.version}" }
s.author = { 'Gustavo Ambrozio' => '', "Barrett Jacobsen" => "[email protected]", "Jose Santiago Jr" => '', 'Taymer Ragazzini' => '[email protected]', 'Pedro Ventura' => '' }
s.source = { :git => 'https://github.com/pventura1976/BlockAlertsAnd-ActionSheets.git', :tag => "#{s.version}" }
s.platform = :ios, '4.3'
s.source_files = "BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.{h,m}", "BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.{h,m}", "BlockAlertsDemo/ToAddToYourProjects/BlockBackground.{h,m}", "BlockAlertsDemo/ToAddToYourProjects/BlockTextPromptAlertView.{h,m}", 'BlockAlertsDemo/ProjectSpecific/BlockUI.h'
s.source_files = "BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.{h,m}", "BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.{h,m}", "BlockAlertsDemo/ToAddToYourProjects/BlockBackground.{h,m}", "BlockAlertsDemo/ToAddToYourProjects/BlockTextPromptAlertView.{h,m}", "BlockAlertsDemo/ProjectSpecific/BlockUI.h"
s.resources = "BlockAlertsDemo/images/button*.png", "BlockAlertsDemo/images/ActionSheet/*.png", "BlockAlertsDemo/images/AlertView/*.png"

s.requires_arc = false
s.subspec 'TableAlertView' do |table|
table.source_files = "BlockAlertsDemo/ToAddToYourProjects/BlockTableAlertView.{h,m}"
end
Expand Down
4 changes: 4 additions & 0 deletions BlockAlertsDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@
EC90169114BB629F00EF52E1 /* Project object */ = {
isa = PBXProject;
attributes = {
<<<<<<< HEAD
LastUpgradeCheck = 0610;
=======
LastUpgradeCheck = 0630;
>>>>>>> gpambrozio/master
ORGANIZATIONNAME = "CodeCrop Software";
};
buildConfigurationList = EC90169414BB629F00EF52E1 /* Build configuration list for PBXProject "BlockAlertsDemo" */;
Expand Down
28 changes: 21 additions & 7 deletions BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,38 @@
@private
UIView *_view;
NSMutableArray *_blocks;
NSMutableArray *_completionBlocks;
CGFloat _height;
UIColor *_tintColor;
}

@property (nonatomic, readonly) UIView *view;
@property (nonatomic, readwrite) BOOL vignetteBackground;
@property(nonatomic, readonly) UIView *view;
@property(nonatomic, readwrite) BOOL vignetteBackground;

+ (id)sheetWithTitle:(NSString *)title;
+ (id)sheetWithTitle:(NSString *)title tintColor:(UIColor *)tintColor textColor:(UIColor *)textColor;
- (id)initWithTitle:(NSString *)title tintColor:(UIColor *)tintColor textColor:(UIColor *)textColor;

- (id)initWithTitle:(NSString *)title;

- (void)setCancelButtonWithTitle:(NSString *) title block:(void (^)()) block;
- (void)setDestructiveButtonWithTitle:(NSString *) title block:(void (^)()) block;
- (void)addButtonWithTitle:(NSString *) title block:(void (^)()) block;
- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block;
- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block;
- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block;
- (void)addButtonWithTitle:(NSString *)title color:(NSString *)color block:(void (^)())block atIndex:(NSInteger)index;

// Add buttons at index with block
- (void)setCancelButtonWithTitle:(NSString *) title atIndex:(NSInteger)index block:(void (^)()) block;
- (void)setDestructiveButtonWithTitle:(NSString *) title atIndex:(NSInteger)index block:(void (^)()) block;
- (void)addButtonWithTitle:(NSString *) title atIndex:(NSInteger)index block:(void (^)()) block;

// Add button with block and animation completion block
- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock;
- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock;
- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock;

// Add button at index with block and animation completion block
- (void)setCancelButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block completion:(void (^)())completionBlock;
- (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block completion:(void (^)())completionBlock;
- (void)addButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block completion:(void (^)())completionBlock;

- (void)showInView:(UIView *)view;

- (NSUInteger)buttonCount;
Expand Down
152 changes: 106 additions & 46 deletions BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,25 @@ @implementation BlockActionSheet

#pragma mark - init

+ (void)initialize
{
if (self == [BlockActionSheet class])
{
+ (void)initialize {
if (self == [BlockActionSheet class]) {
background = [UIImage imageNamed:kActionSheetBackground];
background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kActionSheetBackgroundCapHeight] retain];
titleFont = [kActionSheetTitleFont retain];
buttonFont = [kActionSheetButtonFont retain];
}
}

+ (id)sheetWithTitle:(NSString *)title
{
return [[[BlockActionSheet alloc] initWithTitle:title] autorelease];
+ (id)sheetWithTitle:(NSString *)title {
return [[[BlockActionSheet alloc] initWithTitle:title tintColor:nil textColor:nil] autorelease];
}

- (id)initWithTitle:(NSString *)title
{
if ((self = [super init]))
{
+ (id)sheetWithTitle:(NSString *)title tintColor:(UIColor *)tintColor textColor:(UIColor *)textColor {
return [[[BlockActionSheet alloc] initWithTitle:title tintColor:tintColor textColor:textColor] autorelease];
}

- (id)initWithTitle:(NSString *)title tintColor:(UIColor *)tintColor textColor:(UIColor *)textColor {
if ((self = [super init])) {
UIWindow *parentView = [BlockBackground sharedInstance];
CGRect frame = parentView.bounds;

Expand All @@ -47,27 +46,21 @@ - (id)initWithTitle:(NSString *)title

_blocks = [[NSMutableArray alloc] init];
_height = kActionSheetTopMargin;

if (title)
{
CGSize size;
if (IOS_LESS_THAN_7) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
size = [title sizeWithFont:titleFont constrainedToSize:CGSizeMake(frame.size.width-kActionSheetBorder*2, 1000) lineBreakMode:NSLineBreakByWordWrapping];
#pragma clang diagnostic pop
}
else {
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
size = [title boundingRectWithSize:CGSizeMake(frame.size.width-kAlertViewBorder*2, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSParagraphStyleAttributeName : paragraphStyle, NSFontAttributeName : titleFont} context:nil].size;
size = CGSizeMake(ceilf(size.width), ceilf(size.height));
}
_tintColor = [tintColor retain];
if (title) {
CGSize size = [title sizeWithFont:titleFont
constrainedToSize:CGSizeMake(frame.size.width - kActionSheetBorder * 2, 1000)
lineBreakMode:NSLineBreakByWordWrapping];

UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kActionSheetBorder, _height, frame.size.width-kActionSheetBorder*2, size.height)];
UILabel *labelView =
[[UILabel alloc] initWithFrame:CGRectMake(kActionSheetBorder, _height,
frame.size.width - kActionSheetBorder * 2, size.height)];
labelView.font = titleFont;
labelView.numberOfLines = 0;
labelView.lineBreakMode = NSLineBreakByWordWrapping;
if (textColor)
labelView.textColor = textColor;
else
labelView.textColor = kActionSheetTitleTextColor;
labelView.backgroundColor = [UIColor clearColor];
labelView.textAlignment = NSTextAlignmentCenter;
Expand All @@ -76,7 +69,7 @@ - (id)initWithTitle:(NSString *)title
labelView.text = title;

labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

[_view addSubview:labelView];
[labelView release];

Expand All @@ -88,19 +81,31 @@ - (id)initWithTitle:(NSString *)title
return self;
}

- (void) dealloc
- (void) dealloc
{
[_view release];
[_blocks release];
[_completionBlocks release];
[_tintColor release];
[super dealloc];
}

- (NSUInteger)buttonCount
{
- (NSUInteger)buttonCount {
return _blocks.count;
}

#pragma mark - Add buttons

- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block atIndex:(NSInteger)index
{
[self addButtonWithTitle:title
color:color
block:block
atIndex:index
completion:nil];
}

- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block atIndex:(NSInteger)index completion:(void (^)())completionBlock
{
if (index >= 0)
{
Expand All @@ -110,6 +115,12 @@ - (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void
color,
nil]
atIndex:index];
[_blocks insertObject:[NSArray arrayWithObjects:
completionBlock ? [[completionBlock copy] autorelease] : [NSNull null],
title,
color,
nil]
atIndex:index];
}
else
{
Expand All @@ -118,39 +129,74 @@ - (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void
title,
color,
nil]];
[_completionBlocks addObject:[NSArray arrayWithObjects:
completionBlock ? [[completionBlock copy] autorelease] : [NSNull null],
title,
color,
nil]];
}
}

- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block
{
- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block {
[self addButtonWithTitle:title color:@"red" block:block atIndex:-1];
}

- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block
{
- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block {
[self addButtonWithTitle:title color:@"black" block:block atIndex:-1];
}

- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block
{
- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block {
[self addButtonWithTitle:title color:@"gray" block:block atIndex:-1];
}

- (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block
{
- (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block {
[self addButtonWithTitle:title color:@"red" block:block atIndex:index];
}

- (void)setCancelButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block
{
- (void)setCancelButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block {
[self addButtonWithTitle:title color:@"black" block:block atIndex:index];
}

- (void)addButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block
{
- (void)addButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block {
[self addButtonWithTitle:title color:@"gray" block:block atIndex:index];
}

#pragma mark - Add button with block and animation completion block

- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock
{
[self addButtonWithTitle:title color:@"red" block:block atIndex:-1 completion:completionBlock];
}

- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock
{
[self addButtonWithTitle:title color:@"black" block:block atIndex:-1 completion:completionBlock];
}

- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock
{
[self addButtonWithTitle:title color:@"gray" block:block atIndex:-1 completion:completionBlock];
}

#pragma mark - Add button at index with block and animation completion block

- (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block completion:(void (^)())completionBlock
{
[self addButtonWithTitle:title color:@"red" block:block atIndex:index completion:completionBlock];
}

- (void)setCancelButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block completion:(void (^)())completionBlock
{
[self addButtonWithTitle:title color:@"black" block:block atIndex:index completion:completionBlock];
}

- (void)addButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block completion:(void (^)())completionBlock
{
[self addButtonWithTitle:title color:@"gray" block:block atIndex:index completion:completionBlock];
}

# pragma mark - Show / Hide

- (void)showInView:(UIView *)view
{
NSUInteger i = 1;
Expand Down Expand Up @@ -236,8 +282,9 @@ - (void)showInView:(UIView *)view
[self retain];
}

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
{
// Block Execution
if (buttonIndex >= 0 && buttonIndex < [_blocks count])
{
id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0];
Expand All @@ -258,9 +305,22 @@ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)anim
_view.center = center;
[[BlockBackground sharedInstance] reduceAlphaIfEmpty];
} completion:^(BOOL finished) {

//Completion block execution
if (buttonIndex >= 0 && buttonIndex < [_completionBlocks count])
{
id obj = [[_completionBlocks objectAtIndex: buttonIndex] objectAtIndex:0];
if (![obj isEqual:[NSNull null]])
{
((void (^)())obj)();
}
}

// Release
[[BlockBackground sharedInstance] removeView:_view];
[_view release]; _view = nil;
[self autorelease];

}];
}
else
Expand All @@ -273,7 +333,7 @@ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)anim

#pragma mark - Action

- (void)buttonClicked:(id)sender
- (void)buttonClicked:(id)sender
{
/* Run the button's block */
NSInteger buttonIndex = [(UIButton *)sender tag] - 1;
Expand Down
Loading