From 24fa8d38b5ca5626417263770ff1a3302c9714d8 Mon Sep 17 00:00:00 2001 From: Pedro Ventura Date: Tue, 10 Mar 2015 09:09:27 +0100 Subject: [PATCH 01/32] Added completion block execution --- .../ToAddToYourProjects/BlockActionSheet.h | 13 +++ .../ToAddToYourProjects/BlockActionSheet.m | 79 +++++++++++++++++++ .../ToAddToYourProjects/BlockAlertView.h | 7 ++ .../ToAddToYourProjects/BlockAlertView.m | 47 ++++++++++- 4 files changed, 145 insertions(+), 1 deletion(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h index ef160ce..ff46289 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h @@ -12,6 +12,7 @@ @private UIView *_view; NSMutableArray *_blocks; + NSMutableArray *_completionBlocks; CGFloat _height; } @@ -22,14 +23,26 @@ - (id)initWithTitle:(NSString *)title; +// Add buttons with block - (void)setCancelButtonWithTitle:(NSString *) title block:(void (^)()) block; - (void)setDestructiveButtonWithTitle:(NSString *) title block:(void (^)()) block; - (void)addButtonWithTitle:(NSString *) title block:(void (^)()) block; +// 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; diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m index 222d48c..487aec6 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m @@ -46,6 +46,8 @@ - (id)initWithTitle:(NSString *)title _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; _blocks = [[NSMutableArray alloc] init]; + _completionBlocks = [[NSMutableArray alloc] init]; + _height = kActionSheetTopMargin; if (title) @@ -82,6 +84,7 @@ - (void) dealloc { [_view release]; [_blocks release]; + [_completionBlocks release]; [super dealloc]; } @@ -90,7 +93,18 @@ - (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) { @@ -100,6 +114,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 { @@ -108,9 +128,16 @@ - (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]]; } } +#pragma mark - Add buttons with block + - (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block { [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; @@ -126,6 +153,8 @@ - (void)addButtonWithTitle:(NSString *)title block:(void (^)())block [self addButtonWithTitle:title color:@"gray" block:block atIndex:-1]; } +#pragma mark - Add buttons at index with block + - (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block { [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; @@ -141,6 +170,42 @@ - (void)addButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(voi [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; @@ -228,6 +293,7 @@ - (void)showInView:(UIView *)view - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { + // Block Execution if (buttonIndex >= 0 && buttonIndex < [_blocks count]) { id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; @@ -248,9 +314,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 diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h index 15238de..1121537 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h @@ -9,6 +9,7 @@ @protected UIView *_view; NSMutableArray *_blocks; + NSMutableArray *_completionBlocks; CGFloat _height; NSString *_title; NSString *_message; @@ -23,10 +24,16 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message; +// Add button with block - (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block; - (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block; - (void)addButtonWithTitle:(NSString *)title 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; + // Images should be named in the form "alert-IDENTIFIER-button.png" - (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString*)identifier block:(void (^)())block; diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index bd25de0..6d0736d 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -153,6 +153,7 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message _view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; _blocks = [[NSMutableArray alloc] init]; + _completionBlocks = [[NSMutableArray alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupDisplay) @@ -175,19 +176,30 @@ - (void)dealloc [_backgroundImage release]; [_view release]; [_blocks release]; + [_completionBlocks release]; [super dealloc]; } /////////////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Public -- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block +- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block +{ + [self addButtonWithTitle:title color:color block:block completion:nil]; +} + +- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block completion:(void (^)())completionBlock { [_blocks addObject:[NSArray arrayWithObjects: block ? [[block copy] autorelease] : [NSNull null], title, color, nil]]; + [_completionBlocks addObject:[NSArray arrayWithObjects: + completionBlock ? [[completionBlock copy] autorelease] : [NSNull null], + title, + color, + nil]]; } - (void)addButtonWithTitle:(NSString *)title block:(void (^)())block @@ -209,6 +221,25 @@ - (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString*)identifi [self addButtonWithTitle:title color:identifier block:block]; } +- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock +{ + [self addButtonWithTitle:title color:@"gray" block:block completion:completionBlock]; +} + +- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock +{ + [self addButtonWithTitle:title color:@"black" block:block completion:completionBlock]; +} + +- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock +{ + [self addButtonWithTitle:title color:@"red" block:block completion:completionBlock]; +} + +- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString*)identifier block:(void (^)())block { + [self addButtonWithTitle:title color:identifier block:block]; +} + - (void)show { _shown = YES; @@ -402,6 +433,7 @@ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)anim [[NSNotificationCenter defaultCenter] removeObserver:self]; + // Block execution if (buttonIndex >= 0 && buttonIndex < [_blocks count]) { id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; @@ -432,9 +464,22 @@ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)anim [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; } completion:^(BOOL finished) { + + // Completion block + 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]; + }]; }]; } From a4542d0f8d1d05f0c1d0816fdc9bb1d23cb4c429 Mon Sep 17 00:00:00 2001 From: Pedro Ventura Date: Wed, 11 Mar 2015 09:26:42 +0100 Subject: [PATCH 02/32] Missing completion block --- BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index 6d0736d..306ca0b 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -236,8 +236,8 @@ - (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block [self addButtonWithTitle:title color:@"red" block:block completion:completionBlock]; } -- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString*)identifier block:(void (^)())block { - [self addButtonWithTitle:title color:identifier block:block]; +- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString*)identifier block:(void (^)())block completion:(void (^)())completionBlock { + [self addButtonWithTitle:title color:identifier block:block completion:completionBlock]; } - (void)show From 7e705d420e0f51e5a0db9cb034ed8a06a1060ec2 Mon Sep 17 00:00:00 2001 From: Pedro Ventura Date: Wed, 11 Mar 2015 09:27:22 +0100 Subject: [PATCH 03/32] Project recommended settings --- BlockAlertsDemo.xcodeproj/project.pbxproj | 29 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/BlockAlertsDemo.xcodeproj/project.pbxproj b/BlockAlertsDemo.xcodeproj/project.pbxproj index 3ffe19c..7aaa525 100644 --- a/BlockAlertsDemo.xcodeproj/project.pbxproj +++ b/BlockAlertsDemo.xcodeproj/project.pbxproj @@ -287,7 +287,7 @@ EC90169114BB629F00EF52E1 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0420; + LastUpgradeCheck = 0610; ORGANIZATIONNAME = "CodeCrop Software"; }; buildConfigurationList = EC90169414BB629F00EF52E1 /* Build configuration list for PBXProject "BlockAlertsDemo" */; @@ -393,9 +393,16 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -405,10 +412,15 @@ ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 5.0; + ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; @@ -417,13 +429,24 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 5.0; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; From fdf83b30fb215b9ca0551c0c6cacbf8d9fe68367 Mon Sep 17 00:00:00 2001 From: taymer Date: Wed, 8 Apr 2015 13:33:39 +0200 Subject: [PATCH 04/32] Update BlockAlertView.m --- .../ToAddToYourProjects/BlockAlertView.m | 743 +++++++++--------- 1 file changed, 360 insertions(+), 383 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index bd25de0..9ff9ba9 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -19,441 +19,418 @@ @implementation BlockAlertView static UIFont *messageFont = nil; static UIFont *buttonFont = nil; - #pragma mark - init -+ (void)initialize -{ - if (self == [BlockAlertView class]) - { - background = [UIImage imageNamed:kAlertViewBackground]; - background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; - - backgroundlandscape = [UIImage imageNamed:kAlertViewBackgroundLandscape]; - backgroundlandscape = [[backgroundlandscape stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; - - titleFont = [kAlertViewTitleFont retain]; - messageFont = [kAlertViewMessageFont retain]; - buttonFont = [kAlertViewButtonFont retain]; - } ++ (void)initialize { + if (self == [BlockAlertView class]) { + background = [UIImage imageNamed:kAlertViewBackground]; + background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; + + backgroundlandscape = [UIImage imageNamed:kAlertViewBackgroundLandscape]; + backgroundlandscape = + [[backgroundlandscape stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; + + titleFont = [kAlertViewTitleFont retain]; + messageFont = [kAlertViewMessageFont retain]; + buttonFont = [kAlertViewButtonFont retain]; + } } -+ (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message -{ - return [[[BlockAlertView alloc] initWithTitle:title message:message] autorelease]; ++ (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message { + return [[[BlockAlertView alloc] initWithTitle:title message:message] autorelease]; } -+ (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message -{ - BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:title message:message]; - [alert setCancelButtonWithTitle:NSLocalizedString(@"Dismiss", nil) block:nil]; - [alert show]; - [alert release]; ++ (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message { + BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:title message:message]; + [alert setCancelButtonWithTitle:NSLocalizedString(@"Dismiss", nil) block:nil]; + [alert show]; + [alert release]; } -+ (void)showErrorAlert:(NSError *)error -{ - BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:NSLocalizedString(@"Operation Failed", nil) message:[NSString stringWithFormat:NSLocalizedString(@"The operation did not complete successfully: %@", nil), error]]; - [alert setCancelButtonWithTitle:@"Dismiss" block:nil]; - [alert show]; - [alert release]; ++ (void)showErrorAlert:(NSError *)error { + BlockAlertView *alert = [[BlockAlertView alloc] + initWithTitle:NSLocalizedString(@"Operation Failed", nil) + message:[NSString + stringWithFormat:NSLocalizedString(@"The operation did not complete successfully: %@", nil), + error]]; + [alert setCancelButtonWithTitle:@"Dismiss" block:nil]; + [alert show]; + [alert release]; } /////////////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - NSObject - (void)addComponents:(CGRect)frame { - if (_title) - { - CGSize size = [_title sizeWithFont:titleFont - constrainedToSize:CGSizeMake(frame.size.width-kAlertViewBorder*2, 1000) - lineBreakMode:NSLineBreakByWordWrapping]; - - UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width-kAlertViewBorder*2, size.height)]; - labelView.font = titleFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kAlertViewTitleTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kAlertViewTitleShadowColor; - labelView.shadowOffset = kAlertViewTitleShadowOffset; - labelView.text = _title; - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + kAlertViewBorder; - } - - if (_message) - { - CGSize size = [_message sizeWithFont:messageFont - constrainedToSize:CGSizeMake(frame.size.width-kAlertViewBorder*2, 1000) - lineBreakMode:NSLineBreakByWordWrapping]; - - UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width-kAlertViewBorder*2, size.height)]; - labelView.font = messageFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kAlertViewMessageTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kAlertViewMessageShadowColor; - labelView.shadowOffset = kAlertViewMessageShadowOffset; - labelView.text = _message; - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + kAlertViewBorder; - } + if (_title) { + CGSize size = [_title sizeWithFont:titleFont + constrainedToSize:CGSizeMake(frame.size.width - kAlertViewBorder * 2, 1000) + lineBreakMode:NSLineBreakByWordWrapping]; + + UILabel *labelView = [[UILabel alloc] + initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width - kAlertViewBorder * 2, size.height)]; + labelView.font = titleFont; + labelView.numberOfLines = 0; + labelView.lineBreakMode = NSLineBreakByWordWrapping; + labelView.textColor = kAlertViewTitleTextColor; + labelView.backgroundColor = [UIColor clearColor]; + labelView.textAlignment = NSTextAlignmentCenter; + labelView.shadowColor = kAlertViewTitleShadowColor; + labelView.shadowOffset = kAlertViewTitleShadowOffset; + labelView.text = _title; + [_view addSubview:labelView]; + [labelView release]; + + _height += size.height + kAlertViewBorder; + } + + if (_message) { + CGSize size = [_message sizeWithFont:messageFont + constrainedToSize:CGSizeMake(frame.size.width - kAlertViewBorder * 2, 1000) + lineBreakMode:NSLineBreakByWordWrapping]; + + UILabel *labelView = [[UILabel alloc] + initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width - kAlertViewBorder * 2, size.height)]; + labelView.font = messageFont; + labelView.numberOfLines = 0; + labelView.lineBreakMode = NSLineBreakByWordWrapping; + labelView.textColor = kAlertViewMessageTextColor; + labelView.backgroundColor = [UIColor clearColor]; + labelView.textAlignment = NSTextAlignmentCenter; + labelView.shadowColor = kAlertViewMessageShadowColor; + labelView.shadowOffset = kAlertViewMessageShadowOffset; + labelView.text = _message; + [_view addSubview:labelView]; + [labelView release]; + + _height += size.height + kAlertViewBorder; + } } -- (void)setupDisplay -{ - [[_view subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - [obj removeFromSuperview]; - }]; - - UIWindow *parentView = [BlockBackground sharedInstance]; - CGRect frame = parentView.bounds; - frame.origin.x = floorf((frame.size.width - background.size.width) * 0.5); - frame.size.width = background.size.width; - - UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; - if (UIInterfaceOrientationIsLandscape(orientation)) { - frame.size.width += 150; - frame.origin.x -= 75; - } - - _view.frame = frame; - - _height = kAlertViewBorder + 15; - - if (NeedsLandscapePhoneTweaks) { - _height -= 15; // landscape phones need to trimmed a bit - } +- (void)setupDisplay { + [[_view subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [obj removeFromSuperview]; + }]; - [self addComponents:frame]; + UIWindow *parentView = [BlockBackground sharedInstance]; + CGRect frame = parentView.bounds; + frame.origin.x = floorf((frame.size.width - background.size.width) * 0.5); + frame.size.width = background.size.width; - if (_shown) - [self show]; + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + if (UIInterfaceOrientationIsLandscape(orientation)) { + frame.size.width += 150; + frame.origin.x -= 75; + } + + _view.frame = frame; + + _height = kAlertViewBorder + 15; + + if (NeedsLandscapePhoneTweaks) { + _height -= 15; // landscape phones need to trimmed a bit + } + + [self addComponents:frame]; + + if (_shown) [self show]; } -- (id)initWithTitle:(NSString *)title message:(NSString *)message -{ - self = [super init]; - - if (self) - { - _title = [title copy]; - _message = [message copy]; - - _view = [[UIView alloc] init]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; - - _blocks = [[NSMutableArray alloc] init]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(setupDisplay) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; - - if ([self class] == [BlockAlertView class]) - [self setupDisplay]; - - _vignetteBackground = NO; - } - - return self; +- (id)initWithTitle:(NSString *)title message:(NSString *)message { + self = [super init]; + + if (self) { + _title = [title copy]; + _message = [message copy]; + + _view = [[UIScrollView alloc] init]; + + _view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | + UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; + + _blocks = [[NSMutableArray alloc] init]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(setupDisplay) + name:UIApplicationDidChangeStatusBarOrientationNotification + object:nil]; + + if ([self class] == [BlockAlertView class]) [self setupDisplay]; + + _vignetteBackground = NO; + } + + return self; } -- (void)dealloc -{ - [_title release]; - [_message release]; - [_backgroundImage release]; - [_view release]; - [_blocks release]; - [super dealloc]; +- (void)dealloc { + [_title release]; + [_message release]; + [_backgroundImage release]; + [_view release]; + [_blocks release]; + [super dealloc]; } /////////////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Public -- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block -{ - [_blocks addObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil]]; +- (void)addButtonWithTitle:(NSString *)title color:(NSString *)color block:(void (^)())block { + [_blocks addObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil]]; } -- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"gray" block:block]; +- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block { + [self addButtonWithTitle:title color:@"gray" block:block]; } -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"black" block:block]; +- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block { + [self addButtonWithTitle:title color:@"black" block:block]; } -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"red" block:block]; +- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block { + [self addButtonWithTitle:title color:@"red" block:block]; } -- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString*)identifier block:(void (^)())block { - [self addButtonWithTitle:title color:identifier block:block]; +- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString *)identifier block:(void (^)())block { + [self addButtonWithTitle:title color:identifier block:block]; } -- (void)show -{ - _shown = YES; - - BOOL isSecondButton = NO; - NSUInteger index = 0; - for (NSUInteger i = 0; i < _blocks.count; i++) - { - NSArray *block = [_blocks objectAtIndex:i]; - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width+1)>>1 topCapHeight:0]; - - UIImage *highlightedImage = [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button-highlighted.png", color]]; - - highlightedImage = [highlightedImage stretchableImageWithLeftCapWidth:(int)(highlightedImage.size.width+1)>>1 topCapHeight:0]; - - CGFloat maxHalfWidth = floorf((_view.bounds.size.width-kAlertViewBorder*3)*0.5); - CGFloat width = _view.bounds.size.width-kAlertViewBorder*2; - CGFloat xOffset = kAlertViewBorder; - if (isSecondButton) - { - width = maxHalfWidth; - xOffset = width + kAlertViewBorder * 2; - isSecondButton = NO; - } - else if (i + 1 < _blocks.count) - { - // In this case there's another button. - // Let's check if they fit on the same line. - CGSize size = [title sizeWithFont:buttonFont - minFontSize:10 - actualFontSize:nil - forWidth:_view.bounds.size.width-kAlertViewBorder*2 - lineBreakMode:NSLineBreakByClipping]; - - if (size.width < maxHalfWidth - kAlertViewBorder) - { - // It might fit. Check the next Button - NSArray *block2 = [_blocks objectAtIndex:i+1]; - NSString *title2 = [block2 objectAtIndex:1]; - size = [title2 sizeWithFont:buttonFont - minFontSize:10 - actualFontSize:nil - forWidth:_view.bounds.size.width-kAlertViewBorder*2 - lineBreakMode:NSLineBreakByClipping]; - - if (size.width < maxHalfWidth - kAlertViewBorder) - { - // They'll fit! - isSecondButton = YES; // For the next iteration - width = maxHalfWidth; - } - } +- (void)show { + _shown = YES; + + BOOL isSecondButton = NO; + NSUInteger index = 0; + for (NSUInteger i = 0; i < _blocks.count; i++) { + NSArray *block = [_blocks objectAtIndex:i]; + NSString *title = [block objectAtIndex:1]; + NSString *color = [block objectAtIndex:2]; + + UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button.png", color]]; + image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width + 1) >> 1 topCapHeight:0]; + + UIImage *highlightedImage = + [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button-highlighted.png", color]]; + + highlightedImage = + [highlightedImage stretchableImageWithLeftCapWidth:(int)(highlightedImage.size.width + 1) >> 1 topCapHeight:0]; + + CGFloat maxHalfWidth = floorf((_view.bounds.size.width - kAlertViewBorder * 3) * 0.5); + CGFloat width = _view.bounds.size.width - kAlertViewBorder * 2; + CGFloat xOffset = kAlertViewBorder; + if (isSecondButton) { + width = maxHalfWidth; + xOffset = width + kAlertViewBorder * 2; + isSecondButton = NO; + } else if (i + 1 < _blocks.count) { + // In this case there's another button. + // Let's check if they fit on the same line. + CGSize size = [title sizeWithFont:buttonFont + minFontSize:10 + actualFontSize:nil + forWidth:_view.bounds.size.width - kAlertViewBorder * 2 + lineBreakMode:NSLineBreakByClipping]; + + if (size.width < maxHalfWidth - kAlertViewBorder) { + // It might fit. Check the next Button + NSArray *block2 = [_blocks objectAtIndex:i + 1]; + NSString *title2 = [block2 objectAtIndex:1]; + size = [title2 sizeWithFont:buttonFont + minFontSize:10 + actualFontSize:nil + forWidth:_view.bounds.size.width - kAlertViewBorder * 2 + lineBreakMode:NSLineBreakByClipping]; + + if (size.width < maxHalfWidth - kAlertViewBorder) { + // They'll fit! + isSecondButton = YES; // For the next iteration + width = maxHalfWidth; } - else if (_blocks.count == 1) - { - // In this case this is the ony button. We'll size according to the text - CGSize size = [title sizeWithFont:buttonFont - minFontSize:10 - actualFontSize:nil - forWidth:_view.bounds.size.width-kAlertViewBorder*2 - lineBreakMode:NSLineBreakByClipping]; - - size.width = MAX(size.width, 80); - if (size.width + 2 * kAlertViewBorder < width) - { - width = size.width + 2 * kAlertViewBorder; - xOffset = floorf((_view.bounds.size.width - width) * 0.5); - } - } - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(xOffset, _height, width, kAlertButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { + } + } else if (_blocks.count == 1) { + // In this case this is the ony button. We'll size according to the text + CGSize size = [title sizeWithFont:buttonFont + minFontSize:10 + actualFontSize:nil + forWidth:_view.bounds.size.width - kAlertViewBorder * 2 + lineBreakMode:NSLineBreakByClipping]; + + size.width = MAX(size.width, 80); + if (size.width + 2 * kAlertViewBorder < width) { + width = size.width + 2 * kAlertViewBorder; + xOffset = floorf((_view.bounds.size.width - width) * 0.5); + } + } + + UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; + button.frame = CGRectMake(xOffset, _height, width, kAlertButtonHeight); + button.titleLabel.font = buttonFont; + if (IOS_LESS_THAN_6) { #pragma clan diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; + button.titleLabel.minimumFontSize = 10; #pragma clan diagnostic pop - } - else { - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.adjustsLetterSpacingToFitWidth = YES; - button.titleLabel.minimumScaleFactor = 0.1; - } - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kAlertViewButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i+1; - - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) - { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - } - [button setTitleColor:kAlertViewButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kAlertViewButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - [_view addSubview:button]; - - if (!isSecondButton) - _height += kAlertButtonHeight + kAlertViewBorder; - - index++; + } else { + button.titleLabel.adjustsFontSizeToFitWidth = YES; + button.titleLabel.adjustsLetterSpacingToFitWidth = YES; + button.titleLabel.minimumScaleFactor = 0.1; } - - //_height += 10; // Margin for the shadow // not sure where this came from, but it's making things look strange (I don't see a shadow, either) - - if (_height < background.size.height) - { - CGFloat offset = background.size.height - _height; - _height = background.size.height; - CGRect frame; - for (NSUInteger i = 0; i < _blocks.count; i++) - { - UIButton *btn = (UIButton *)[_view viewWithTag:i+1]; - frame = btn.frame; - frame.origin.y += offset; - btn.frame = frame; - } + button.titleLabel.textAlignment = NSTextAlignmentCenter; + button.titleLabel.shadowOffset = kAlertViewButtonShadowOffset; + button.backgroundColor = [UIColor clearColor]; + button.tag = i + 1; + + [button setBackgroundImage:image forState:UIControlStateNormal]; + if (highlightedImage) { + [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; } - - - CGRect frame = _view.frame; - frame.origin.y = - _height; - frame.size.height = _height; - _view.frame = frame; - - UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; - - if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) - modalBackground.image = backgroundlandscape; - else - modalBackground.image = background; - - modalBackground.contentMode = UIViewContentModeScaleToFill; - modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [_view insertSubview:modalBackground atIndex:0]; - [modalBackground release]; - - if (_backgroundImage) - { - [BlockBackground sharedInstance].backgroundImage = _backgroundImage; - [_backgroundImage release]; - _backgroundImage = nil; - } - - [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; - [[BlockBackground sharedInstance] addToMainWindow:_view]; - - __block CGPoint center = _view.center; - center.y = floorf([BlockBackground sharedInstance].bounds.size.height * 0.5) + kAlertViewBounce; - - _cancelBounce = NO; - - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [BlockBackground sharedInstance].alpha = 1.0f; - _view.center = center; - } - completion:^(BOOL finished) { - if (_cancelBounce) return; - - [UIView animateWithDuration:0.1 - delay:0.0 - options:0 - animations:^{ - center.y -= kAlertViewBounce; - _view.center = center; - } - completion:^(BOOL finished) { - [[NSNotificationCenter defaultCenter] postNotificationName:@"AlertViewFinishedAnimations" object:self]; - }]; - }]; - - [self retain]; -} + [button setTitleColor:kAlertViewButtonTextColor forState:UIControlStateNormal]; + [button setTitleShadowColor:kAlertViewButtonShadowColor forState:UIControlStateNormal]; + [button setTitle:title forState:UIControlStateNormal]; + button.accessibilityLabel = title; -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated -{ - _shown = NO; - - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) - { - id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) - { - ((void (^)())obj)(); - } + [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; + + [_view addSubview:button]; + + if (!isSecondButton) _height += kAlertButtonHeight + kAlertViewBorder; + + index++; + } + + //_height += 10; // Margin for the shadow // not sure where this came from, but it's making things look strange (I + // don't see a shadow, either) + + if (_height < background.size.height) { + CGFloat offset = background.size.height - _height; + _height = background.size.height; + CGRect frame; + for (NSUInteger i = 0; i < _blocks.count; i++) { + UIButton *btn = (UIButton *)[_view viewWithTag:i + 1]; + frame = btn.frame; + frame.origin.y += offset; + btn.frame = frame; } - - if (animated) - { + } + + // Ragta: aggiungo qua: + UIWindow *parentView = [BlockBackground sharedInstance]; + if (_height > parentView.bounds.size.height) { + CGSize csize = _view.contentSize; + csize.height = _height; + _view.contentSize = csize; + _height = parentView.bounds.size.height; + } + + // fine Ragta + CGRect frame = _view.frame; + frame.origin.y = -_height; + frame.size.height = _height; + _view.frame = frame; + + UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; + + if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) + modalBackground.image = backgroundlandscape; + else + modalBackground.image = background; + + modalBackground.contentMode = UIViewContentModeScaleToFill; + modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [_view insertSubview:modalBackground atIndex:0]; + [modalBackground release]; + + if (_backgroundImage) { + [BlockBackground sharedInstance].backgroundImage = _backgroundImage; + [_backgroundImage release]; + _backgroundImage = nil; + } + + [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; + [[BlockBackground sharedInstance] addToMainWindow:_view]; + + __block CGPoint center = _view.center; + center.y = floorf([BlockBackground sharedInstance].bounds.size.height * 0.5) + kAlertViewBounce; + + _cancelBounce = NO; + + [UIView animateWithDuration:0.4 + delay:0.0 + options:UIViewAnimationOptionCurveEaseOut + animations:^{ + [BlockBackground sharedInstance].alpha = 1.0f; + _view.center = center; + } + completion:^(BOOL finished) { + if (_cancelBounce) return; + [UIView animateWithDuration:0.1 - delay:0.0 - options:0 - animations:^{ - CGPoint center = _view.center; - center.y += 20; - _view.center = center; - } - completion:^(BOOL finished) { - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseIn - animations:^{ - CGRect frame = _view.frame; - frame.origin.y = -frame.size.height; - _view.frame = frame; - [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; - } - completion:^(BOOL finished) { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; - }]; - }]; - } - else - { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; + delay:0.0 + options:0 + animations:^{ + center.y -= kAlertViewBounce; + _view.center = center; + } + completion:^(BOOL finished) { + [[NSNotificationCenter defaultCenter] postNotificationName:@"AlertViewFinishedAnimations" object:self]; + }]; + }]; + + [self retain]; +} + +- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { + _shown = NO; + + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + if (buttonIndex >= 0 && buttonIndex < [_blocks count]) { + id obj = [[_blocks objectAtIndex:buttonIndex] objectAtIndex:0]; + if (![obj isEqual:[NSNull null]]) { + ((void (^)())obj)(); } + } + + if (animated) { + [UIView animateWithDuration:0.1 + delay:0.0 + options:0 + animations:^{ + CGPoint center = _view.center; + center.y += 20; + _view.center = center; + } + completion:^(BOOL finished) { + [UIView animateWithDuration:0.4 + delay:0.0 + options:UIViewAnimationOptionCurveEaseIn + animations:^{ + CGRect frame = _view.frame; + frame.origin.y = -frame.size.height; + _view.frame = frame; + [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; + } + completion:^(BOOL finished) { + [[BlockBackground sharedInstance] removeView:_view]; + [_view release]; + _view = nil; + [self autorelease]; + }]; + }]; + } else { + [[BlockBackground sharedInstance] removeView:_view]; + [_view release]; + _view = nil; + [self autorelease]; + } } /////////////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - Action -- (void)buttonClicked:(id)sender -{ - /* Run the button's block */ - int buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; +- (void)buttonClicked:(id)sender { + /* Run the button's block */ + int buttonIndex = [(UIButton *)sender tag] - 1; + [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; } @end From 44a7b8fbe3873cafab76becb5fdbfabb61623c07 Mon Sep 17 00:00:00 2001 From: taymer Date: Wed, 8 Apr 2015 13:33:58 +0200 Subject: [PATCH 05/32] Update BlockAlertView.h --- .../ToAddToYourProjects/BlockAlertView.h | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h index 15238de..4ebefe2 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h @@ -6,18 +6,17 @@ #import @interface BlockAlertView : NSObject { -@protected - UIView *_view; - NSMutableArray *_blocks; - CGFloat _height; - NSString *_title; - NSString *_message; - BOOL _shown; - BOOL _cancelBounce; + @protected + UIScrollView *_view; + NSMutableArray *_blocks; + CGFloat _height; + NSString *_title; + NSString *_message; + BOOL _shown; + BOOL _cancelBounce; } + (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message; - + (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message; + (void)showErrorAlert:(NSError *)error; @@ -28,7 +27,7 @@ - (void)addButtonWithTitle:(NSString *)title block:(void (^)())block; // Images should be named in the form "alert-IDENTIFIER-button.png" -- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString*)identifier block:(void (^)())block; +- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString *)identifier block:(void (^)())block; - (void)addComponents:(CGRect)frame; @@ -37,8 +36,8 @@ - (void)setupDisplay; -@property (nonatomic, retain) UIImage *backgroundImage; -@property (nonatomic, readonly) UIView *view; -@property (nonatomic, readwrite) BOOL vignetteBackground; +@property(nonatomic, retain) UIImage *backgroundImage; +@property(nonatomic, readonly) UIScrollView *view; +@property(nonatomic, readwrite) BOOL vignetteBackground; @end From 425cccf3f4066c3210f6840d82fc9970f652238b Mon Sep 17 00:00:00 2001 From: taymer Date: Wed, 8 Apr 2015 13:42:17 +0200 Subject: [PATCH 06/32] Update BlockAlertsAnd-ActionSheets.podspec --- BlockAlertsAnd-ActionSheets.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BlockAlertsAnd-ActionSheets.podspec b/BlockAlertsAnd-ActionSheets.podspec index 0debc6c..6080777 100644 --- a/BlockAlertsAnd-ActionSheets.podspec +++ b/BlockAlertsAnd-ActionSheets.podspec @@ -2,10 +2,10 @@ Pod::Spec.new do |s| s.name = "BlockAlertsAnd-ActionSheets" s.version = "1.0.6" s.summary = 'Beautifully done UIAlertView and UIActionSheet replacements inspired by TweetBot.' - s.homepage = "https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets" + s.homepage = "https://github.com/taymer/BlockAlertsAnd-ActionSheets" s.license = 'MIT' - s.author = { 'Gustavo Ambrozio' => '', "Barrett Jacobsen" => "admin@barrettj.com", "Jose Santiago Jr" => '' } - s.source = { :git => 'https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets.git', :tag => "#{s.version}" } + s.author = { 'Gustavo Ambrozio' => '', "Barrett Jacobsen" => "admin@barrettj.com", "Jose Santiago Jr" => '', 'Taymer Ragazzini' => 'tragazzini@gmail.com' } + s.source = { :git => 'https://github.com/taymer/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.resources = "BlockAlertsDemo/images/button*.png", "BlockAlertsDemo/images/ActionSheet/*.png", "BlockAlertsDemo/images/AlertView/*.png" From d5231cebf95dbab962c3d9c882c484aaf4ef4149 Mon Sep 17 00:00:00 2001 From: taymer Date: Wed, 8 Apr 2015 13:42:41 +0200 Subject: [PATCH 07/32] Update BlockAlertsAnd-ActionSheets.podspec --- BlockAlertsAnd-ActionSheets.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlockAlertsAnd-ActionSheets.podspec b/BlockAlertsAnd-ActionSheets.podspec index 6080777..0a46cee 100644 --- a/BlockAlertsAnd-ActionSheets.podspec +++ b/BlockAlertsAnd-ActionSheets.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "BlockAlertsAnd-ActionSheets" - s.version = "1.0.6" + s.version = "1.0.7" s.summary = 'Beautifully done UIAlertView and UIActionSheet replacements inspired by TweetBot.' s.homepage = "https://github.com/taymer/BlockAlertsAnd-ActionSheets" s.license = 'MIT' From 39cf8c5cb8bcf969e785c4a02077c2c5381481ea Mon Sep 17 00:00:00 2001 From: taymer Date: Wed, 8 Apr 2015 13:57:42 +0200 Subject: [PATCH 08/32] Update BlockAlertsAnd-ActionSheets.podspec --- BlockAlertsAnd-ActionSheets.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlockAlertsAnd-ActionSheets.podspec b/BlockAlertsAnd-ActionSheets.podspec index 0a46cee..806cf2c 100644 --- a/BlockAlertsAnd-ActionSheets.podspec +++ b/BlockAlertsAnd-ActionSheets.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |s| 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.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 From 5e7e1b72a3ea46b45a1a248e0fc7c7eba77ac2b4 Mon Sep 17 00:00:00 2001 From: taymer Date: Wed, 8 Apr 2015 15:12:18 +0200 Subject: [PATCH 09/32] Update BlockAlertView.h --- BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h | 1 + 1 file changed, 1 insertion(+) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h index 4ebefe2..5a33b3b 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h @@ -39,5 +39,6 @@ @property(nonatomic, retain) UIImage *backgroundImage; @property(nonatomic, readonly) UIScrollView *view; @property(nonatomic, readwrite) BOOL vignetteBackground; +@property(nonatomic, retain) UIColor *tintColor; @end From 27f26d8408a376860b817999e87b18d0b08c9384 Mon Sep 17 00:00:00 2001 From: taymer Date: Wed, 8 Apr 2015 15:12:35 +0200 Subject: [PATCH 10/32] Update BlockAlertView.m --- .../ToAddToYourProjects/BlockAlertView.m | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index 9ff9ba9..b1721f2 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -12,6 +12,7 @@ @implementation BlockAlertView @synthesize view = _view; @synthesize backgroundImage = _backgroundImage; @synthesize vignetteBackground = _vignetteBackground; +@synthesize tintColor = _tintColor; static UIImage *background = nil; static UIImage *backgroundlandscape = nil; @@ -299,7 +300,6 @@ - (void)show { //_height += 10; // Margin for the shadow // not sure where this came from, but it's making things look strange (I // don't see a shadow, either) - if (_height < background.size.height) { CGFloat offset = background.size.height - _height; _height = background.size.height; @@ -313,6 +313,7 @@ - (void)show { } // Ragta: aggiungo qua: + CGFloat heightBackground = _height; UIWindow *parentView = [BlockBackground sharedInstance]; if (_height > parentView.bounds.size.height) { CGSize csize = _view.contentSize; @@ -321,19 +322,26 @@ - (void)show { _height = parentView.bounds.size.height; } - // fine Ragta CGRect frame = _view.frame; frame.origin.y = -_height; frame.size.height = _height; _view.frame = frame; - UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; + // UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; + UIImageView *modalBackground = + [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, heightBackground)]; if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) modalBackground.image = backgroundlandscape; else modalBackground.image = background; + if (_tintColor) { + modalBackground.image = [modalBackground.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; + modalBackground.tintColor = _tintColor; + } + // fine Ragta + modalBackground.contentMode = UIViewContentModeScaleToFill; modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [_view insertSubview:modalBackground atIndex:0]; From 9608b80a946ba100700c208a8cacbe42c4bfea26 Mon Sep 17 00:00:00 2001 From: taymer Date: Tue, 5 May 2015 16:18:30 +0200 Subject: [PATCH 11/32] Update BlockAlertView.h Added text and title colors --- BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h index 5a33b3b..011b709 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h @@ -40,5 +40,7 @@ @property(nonatomic, readonly) UIScrollView *view; @property(nonatomic, readwrite) BOOL vignetteBackground; @property(nonatomic, retain) UIColor *tintColor; +@property(nonatomic, retain) UIColor *textColor; +@property(nonatomic, retain) UIColor *titleColor; @end From 4903a3783f33da4f201d4f07902f62fad17899d6 Mon Sep 17 00:00:00 2001 From: taymer Date: Tue, 5 May 2015 16:19:07 +0200 Subject: [PATCH 12/32] Update BlockAlertView.m Added text and title colors --- BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index b1721f2..4b6e52e 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -13,6 +13,7 @@ @implementation BlockAlertView @synthesize backgroundImage = _backgroundImage; @synthesize vignetteBackground = _vignetteBackground; @synthesize tintColor = _tintColor; +@synthesize textColor = _textColor, titleColor = _titleColor; static UIImage *background = nil; static UIImage *backgroundlandscape = nil; @@ -73,7 +74,7 @@ - (void)addComponents:(CGRect)frame { labelView.font = titleFont; labelView.numberOfLines = 0; labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kAlertViewTitleTextColor; + labelView.textColor = self.titleColor; labelView.backgroundColor = [UIColor clearColor]; labelView.textAlignment = NSTextAlignmentCenter; labelView.shadowColor = kAlertViewTitleShadowColor; @@ -95,7 +96,7 @@ - (void)addComponents:(CGRect)frame { labelView.font = messageFont; labelView.numberOfLines = 0; labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kAlertViewMessageTextColor; + labelView.textColor = self.textColor; labelView.backgroundColor = [UIColor clearColor]; labelView.textAlignment = NSTextAlignmentCenter; labelView.shadowColor = kAlertViewMessageShadowColor; @@ -155,7 +156,8 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message { selector:@selector(setupDisplay) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; - + self.titleColor = kAlertViewTitleTextColor; + self.textColor = kAlertViewMessageTextColor; if ([self class] == [BlockAlertView class]) [self setupDisplay]; _vignetteBackground = NO; From e32e3b1118ebb04d1a87439d53ce35dc10c8b55a Mon Sep 17 00:00:00 2001 From: taymer Date: Tue, 5 May 2015 16:22:02 +0200 Subject: [PATCH 13/32] Update BlockBackground.m Reported corrections --- .../ToAddToYourProjects/BlockBackground.m | 351 +++++++++--------- 1 file changed, 174 insertions(+), 177 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m b/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m index 79093cc..0f3a415 100644 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m @@ -15,215 +15,212 @@ @implementation BlockBackground static BlockBackground *_sharedInstance = nil; -+ (BlockBackground*)sharedInstance -{ - if (_sharedInstance != nil) { - return _sharedInstance; - } ++ (BlockBackground *)sharedInstance { + if (_sharedInstance != nil) { + return _sharedInstance; + } - @synchronized(self) { - if (_sharedInstance == nil) { - _sharedInstance = [[self alloc] init]; - } + @synchronized(self) { + if (_sharedInstance == nil) { + _sharedInstance = [[self alloc] init]; } - - return _sharedInstance; + } + + return _sharedInstance; } -+ (id)allocWithZone:(NSZone*)zone -{ - @synchronized(self) { - if (_sharedInstance == nil) { - _sharedInstance = [super allocWithZone:zone]; - return _sharedInstance; - } ++ (id)allocWithZone:(NSZone *)zone { + @synchronized(self) { + if (_sharedInstance == nil) { + _sharedInstance = [super allocWithZone:zone]; + return _sharedInstance; } - NSAssert(NO, @ "[BlockBackground alloc] explicitly called on singleton class."); - return nil; + } + NSAssert(NO, @"[BlockBackground alloc] explicitly called on singleton class."); + return nil; } -- (id)copyWithZone:(NSZone*)zone -{ - return self; +- (id)copyWithZone:(NSZone *)zone { + return self; } -- (id)retain -{ - return self; +- (id)retain { + return self; } -- (unsigned)retainCount -{ - return UINT_MAX; +- (unsigned)retainCount { + return UINT_MAX; } -- (oneway void)release -{ +- (oneway void)release { } -- (id)autorelease -{ - return self; +- (id)autorelease { + return self; } -- (void)setRotation:(NSNotification*)notification -{ - UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; - - CGRect orientationFrame = [UIScreen mainScreen].bounds; - - if( - (UIInterfaceOrientationIsLandscape(orientation) && orientationFrame.size.height > orientationFrame.size.width) || - (UIInterfaceOrientationIsPortrait(orientation) && orientationFrame.size.width > orientationFrame.size.height) - ) { - float temp = orientationFrame.size.width; - orientationFrame.size.width = orientationFrame.size.height; - orientationFrame.size.height = temp; +- (void)setRotation:(NSNotification *)notification { + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + + CGRect orientationFrame = [UIScreen mainScreen].bounds; + + if ((UIInterfaceOrientationIsLandscape(orientation) && orientationFrame.size.height > orientationFrame.size.width) || + (UIInterfaceOrientationIsPortrait(orientation) && orientationFrame.size.width > orientationFrame.size.height)) { + float temp = orientationFrame.size.width; + orientationFrame.size.width = orientationFrame.size.height; + orientationFrame.size.height = temp; + } + + self.transform = CGAffineTransformIdentity; + self.frame = orientationFrame; + + CGFloat posY = orientationFrame.size.height / 2; + CGFloat posX = orientationFrame.size.width / 2; + + CGPoint newCenter; + CGFloat rotateAngle; + + switch (orientation) { + case UIInterfaceOrientationPortraitUpsideDown: + rotateAngle = M_PI; + newCenter = CGPointMake(posX, orientationFrame.size.height - posY); + break; + case UIInterfaceOrientationLandscapeLeft: + rotateAngle = -M_PI / 2.0f; + newCenter = CGPointMake(posY, posX); + break; + case UIInterfaceOrientationLandscapeRight: + rotateAngle = M_PI / 2.0f; + newCenter = CGPointMake(orientationFrame.size.height - posY, posX); + break; + default: // UIInterfaceOrientationPortrait + rotateAngle = 0.0; + newCenter = CGPointMake(posX, posY); + break; + } + + if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending) { + if (UIInterfaceOrientationIsLandscape(orientation)) { + newCenter = CGPointMake(newCenter.y, newCenter.x); } - - self.transform = CGAffineTransformIdentity; - self.frame = orientationFrame; - - CGFloat posY = orientationFrame.size.height/2; - CGFloat posX = orientationFrame.size.width/2; - - CGPoint newCenter; - CGFloat rotateAngle; - - switch (orientation) { - case UIInterfaceOrientationPortraitUpsideDown: - rotateAngle = M_PI; - newCenter = CGPointMake(posX, orientationFrame.size.height-posY); - break; - case UIInterfaceOrientationLandscapeLeft: - rotateAngle = -M_PI/2.0f; - newCenter = CGPointMake(posY, posX); - break; - case UIInterfaceOrientationLandscapeRight: - rotateAngle = M_PI/2.0f; - newCenter = CGPointMake(orientationFrame.size.height-posY, posX); - break; - default: // UIInterfaceOrientationPortrait - rotateAngle = 0.0; - newCenter = CGPointMake(posX, posY); - break; - } - - self.transform = CGAffineTransformMakeRotation(rotateAngle); - self.center = newCenter; - - [self setNeedsLayout]; - [self layoutSubviews]; -} + rotateAngle = 0; + } -- (id)init -{ - self = [super initWithFrame:[[UIScreen mainScreen] bounds]]; - if (self) { - self.windowLevel = UIWindowLevelStatusBar; - self.hidden = YES; - self.userInteractionEnabled = NO; - self.backgroundColor = [UIColor colorWithWhite:0.4 alpha:0.5f]; - self.vignetteBackground = NO; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(setRotation:) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; - [self setRotation:nil]; + self.transform = CGAffineTransformMakeRotation(rotateAngle); + self.center = newCenter; - } - return self; + [self setNeedsLayout]; + [self layoutSubviews]; } -- (void)addToMainWindow:(UIView *)view -{ - [self setRotation:nil]; - - if ([self.subviews containsObject:view]) return; - - if (self.hidden) - { - _previousKeyWindow = [[[UIApplication sharedApplication] keyWindow] retain]; - self.alpha = 0.0f; - self.hidden = NO; - [self makeKeyWindow]; - } - - // if something's been added to this window, then this window should have interaction - self.userInteractionEnabled = YES; - - if (self.subviews.count > 0) - { - ((UIView*)[self.subviews lastObject]).userInteractionEnabled = NO; - } - - if (_backgroundImage) - { - UIImageView *backgroundView = [[UIImageView alloc] initWithImage:_backgroundImage]; - backgroundView.frame = self.bounds; - backgroundView.contentMode = UIViewContentModeScaleToFill; - [self addSubview:backgroundView]; - [backgroundView release]; - [_backgroundImage release]; - _backgroundImage = nil; +- (id)init { + self = [super initWithFrame:[[UIScreen mainScreen] bounds]]; + if (self) { + self.windowLevel = UIWindowLevelStatusBar; + self.hidden = YES; + self.userInteractionEnabled = NO; + self.backgroundColor = [UIColor colorWithWhite:0.4 alpha:0.5f]; + self.vignetteBackground = NO; + + if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending) { + UIViewController *temp = [UIViewController new]; + self.rootViewController = temp; } - - [self addSubview:view]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(setRotation:) + name:UIApplicationDidChangeStatusBarOrientationNotification + object:nil]; + [self setRotation:nil]; + } + return self; } -- (void)reduceAlphaIfEmpty -{ - if (self.subviews.count == 1 || (self.subviews.count == 2 && [[self.subviews objectAtIndex:0] isKindOfClass:[UIImageView class]])) - { - self.alpha = 0.0f; - self.userInteractionEnabled = NO; - } +- (void)addToMainWindow:(UIView *)view { + [self setRotation:nil]; + + if ([self.subviews containsObject:view]) return; + + if (self.hidden) { + _previousKeyWindow = [[[UIApplication sharedApplication] keyWindow] retain]; + self.alpha = 0.0f; + self.hidden = NO; + [self makeKeyWindow]; + } + + // if something's been added to this window, then this window should have interaction + self.userInteractionEnabled = YES; + + if (self.subviews.count > 0) { + ((UIView *)[self.subviews lastObject]).userInteractionEnabled = NO; + } + + if (_backgroundImage) { + UIImageView *backgroundView = [[UIImageView alloc] initWithImage:_backgroundImage]; + backgroundView.frame = self.bounds; + backgroundView.contentMode = UIViewContentModeScaleToFill; + [self addSubview:backgroundView]; + [backgroundView release]; + [_backgroundImage release]; + _backgroundImage = nil; + } + + [self addSubview:view]; } -- (void)removeView:(UIView *)view -{ - [view removeFromSuperview]; +- (void)reduceAlphaIfEmpty { + NSMutableArray *remainingViews = NSMutableArray.new; - UIView *topView = [self.subviews lastObject]; - if ([topView isKindOfClass:[UIImageView class]]) - { - // It's a background. Remove it too - [topView removeFromSuperview]; + for (UIView *view in self.subviews) { + if ([view isKindOfClass:[UIImageView class]]) { + // do nothing, this is the background + } else if (CGRectEqualToRect(view.bounds, self.bounds)) { + // also do nothing, this is a different type of background + } else { + [remainingViews addObject:view]; } - - if (self.subviews.count == 0) - { - self.hidden = YES; - [_previousKeyWindow makeKeyWindow]; - [_previousKeyWindow release]; - _previousKeyWindow = nil; - } - else - { - ((UIView*)[self.subviews lastObject]).userInteractionEnabled = YES; - } -} + } -- (void)drawRect:(CGRect)rect -{ - if (_backgroundImage || !_vignetteBackground) return; - CGContextRef context = UIGraphicsGetCurrentContext(); - - size_t locationsCount = 2; - CGFloat locations[2] = {0.0f, 1.0f}; - CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f}; - CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount); - CGColorSpaceRelease(colorSpace); - - CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); - float radius = MIN(self.bounds.size.width , self.bounds.size.height) ; - CGContextDrawRadialGradient (context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation); - CGGradientRelease(gradient); + if (remainingViews.count == 1) { + self.alpha = 0.0f; + self.userInteractionEnabled = NO; + } } +- (void)removeView:(UIView *)view { + [view removeFromSuperview]; + + UIView *topView = [self.subviews lastObject]; + if ([topView isKindOfClass:[UIImageView class]]) { + // It's a background. Remove it too + [topView removeFromSuperview]; + } + + if (self.subviews.count == 0) { + self.hidden = YES; + [_previousKeyWindow makeKeyWindow]; + [_previousKeyWindow release]; + _previousKeyWindow = nil; + } else { + ((UIView *)[self.subviews lastObject]).userInteractionEnabled = YES; + } +} - +- (void)drawRect:(CGRect)rect { + if (_backgroundImage || !_vignetteBackground) return; + CGContextRef context = UIGraphicsGetCurrentContext(); + + size_t locationsCount = 2; + CGFloat locations[2] = {0.0f, 1.0f}; + CGFloat colors[8] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f}; + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount); + CGColorSpaceRelease(colorSpace); + + CGPoint center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2); + float radius = MIN(self.bounds.size.width, self.bounds.size.height); + CGContextDrawRadialGradient(context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation); + CGGradientRelease(gradient); +} @end From 6b407a8874ed1f44733a7557d837d08af82241f0 Mon Sep 17 00:00:00 2001 From: taymer Date: Tue, 5 May 2015 16:22:23 +0200 Subject: [PATCH 14/32] Update BlockAlertsAnd-ActionSheets.podspec --- BlockAlertsAnd-ActionSheets.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlockAlertsAnd-ActionSheets.podspec b/BlockAlertsAnd-ActionSheets.podspec index 806cf2c..9d2b05b 100644 --- a/BlockAlertsAnd-ActionSheets.podspec +++ b/BlockAlertsAnd-ActionSheets.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "BlockAlertsAnd-ActionSheets" - s.version = "1.0.7" + s.version = "1.0.8" s.summary = 'Beautifully done UIAlertView and UIActionSheet replacements inspired by TweetBot.' s.homepage = "https://github.com/taymer/BlockAlertsAnd-ActionSheets" s.license = 'MIT' From ed791869cabe1971dbfabc9e0baaae3fd6545585 Mon Sep 17 00:00:00 2001 From: taymer Date: Thu, 7 May 2015 10:01:01 +0200 Subject: [PATCH 15/32] Update BlockBackground.m --- .../ToAddToYourProjects/BlockBackground.m | 382 ++++++++++-------- 1 file changed, 208 insertions(+), 174 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m b/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m index 0f3a415..0b49afc 100644 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockBackground.m @@ -15,212 +15,246 @@ @implementation BlockBackground static BlockBackground *_sharedInstance = nil; -+ (BlockBackground *)sharedInstance { - if (_sharedInstance != nil) { - return _sharedInstance; - } - - @synchronized(self) { - if (_sharedInstance == nil) { - _sharedInstance = [[self alloc] init]; ++ (BlockBackground*)sharedInstance +{ + if (_sharedInstance != nil) { + return _sharedInstance; } - } - return _sharedInstance; + @synchronized(self) { + if (_sharedInstance == nil) { + _sharedInstance = [[self alloc] init]; + } + } + + return _sharedInstance; } -+ (id)allocWithZone:(NSZone *)zone { - @synchronized(self) { - if (_sharedInstance == nil) { - _sharedInstance = [super allocWithZone:zone]; - return _sharedInstance; ++ (id)allocWithZone:(NSZone*)zone +{ + @synchronized(self) { + if (_sharedInstance == nil) { + _sharedInstance = [super allocWithZone:zone]; + return _sharedInstance; + } } - } - NSAssert(NO, @"[BlockBackground alloc] explicitly called on singleton class."); - return nil; + NSAssert(NO, @ "[BlockBackground alloc] explicitly called on singleton class."); + return nil; } -- (id)copyWithZone:(NSZone *)zone { - return self; +- (id)copyWithZone:(NSZone*)zone +{ + return self; } -- (id)retain { - return self; +- (id)retain +{ + return self; } -- (unsigned)retainCount { - return UINT_MAX; +- (unsigned)retainCount +{ + return UINT_MAX; } -- (oneway void)release { +- (oneway void)release +{ } -- (id)autorelease { - return self; +- (id)autorelease +{ + return self; } -- (void)setRotation:(NSNotification *)notification { - UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; - - CGRect orientationFrame = [UIScreen mainScreen].bounds; - - if ((UIInterfaceOrientationIsLandscape(orientation) && orientationFrame.size.height > orientationFrame.size.width) || - (UIInterfaceOrientationIsPortrait(orientation) && orientationFrame.size.width > orientationFrame.size.height)) { - float temp = orientationFrame.size.width; - orientationFrame.size.width = orientationFrame.size.height; - orientationFrame.size.height = temp; - } - - self.transform = CGAffineTransformIdentity; - self.frame = orientationFrame; - - CGFloat posY = orientationFrame.size.height / 2; - CGFloat posX = orientationFrame.size.width / 2; - - CGPoint newCenter; - CGFloat rotateAngle; - - switch (orientation) { - case UIInterfaceOrientationPortraitUpsideDown: - rotateAngle = M_PI; - newCenter = CGPointMake(posX, orientationFrame.size.height - posY); - break; - case UIInterfaceOrientationLandscapeLeft: - rotateAngle = -M_PI / 2.0f; - newCenter = CGPointMake(posY, posX); - break; - case UIInterfaceOrientationLandscapeRight: - rotateAngle = M_PI / 2.0f; - newCenter = CGPointMake(orientationFrame.size.height - posY, posX); - break; - default: // UIInterfaceOrientationPortrait - rotateAngle = 0.0; - newCenter = CGPointMake(posX, posY); - break; - } - - if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending) { - if (UIInterfaceOrientationIsLandscape(orientation)) { - newCenter = CGPointMake(newCenter.y, newCenter.x); - } - rotateAngle = 0; - } - - self.transform = CGAffineTransformMakeRotation(rotateAngle); - self.center = newCenter; - - [self setNeedsLayout]; - [self layoutSubviews]; +- (void)setRotation:(NSNotification*)notification +{ + if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending){ + return; + } + + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + + CGRect orientationFrame = [UIScreen mainScreen].bounds; + + if( + (UIInterfaceOrientationIsLandscape(orientation) && orientationFrame.size.height > orientationFrame.size.width) || + (UIInterfaceOrientationIsPortrait(orientation) && orientationFrame.size.width > orientationFrame.size.height) + ) { + float temp = orientationFrame.size.width; + orientationFrame.size.width = orientationFrame.size.height; + orientationFrame.size.height = temp; + } + + self.transform = CGAffineTransformIdentity; + self.frame = orientationFrame; + + CGFloat posY = orientationFrame.size.height/2; + CGFloat posX = orientationFrame.size.width/2; + + CGPoint newCenter; + CGFloat rotateAngle; + + switch (orientation) { + case UIInterfaceOrientationPortraitUpsideDown: + rotateAngle = M_PI; + newCenter = CGPointMake(posX, orientationFrame.size.height-posY); + break; + case UIInterfaceOrientationLandscapeLeft: + rotateAngle = -M_PI/2.0f; + newCenter = CGPointMake(posY, posX); + break; + case UIInterfaceOrientationLandscapeRight: + rotateAngle = M_PI/2.0f; + newCenter = CGPointMake(orientationFrame.size.height-posY, posX); + break; + default: // UIInterfaceOrientationPortrait + rotateAngle = 0.0; + newCenter = CGPointMake(posX, posY); + break; + } + + if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending){ + if(UIInterfaceOrientationIsLandscape(orientation)) { + newCenter = CGPointMake(newCenter.y, newCenter.x); + } + rotateAngle = 0; + } + + self.transform = CGAffineTransformMakeRotation(rotateAngle); + self.center = newCenter; + + [self setNeedsLayout]; + [self layoutSubviews]; } -- (id)init { - self = [super initWithFrame:[[UIScreen mainScreen] bounds]]; - if (self) { - self.windowLevel = UIWindowLevelStatusBar; - self.hidden = YES; - self.userInteractionEnabled = NO; - self.backgroundColor = [UIColor colorWithWhite:0.4 alpha:0.5f]; - self.vignetteBackground = NO; +- (id)init +{ + self = [super initWithFrame:[[UIScreen mainScreen] bounds]]; + if (self) { + self.windowLevel = UIWindowLevelStatusBar; + self.hidden = YES; + self.userInteractionEnabled = NO; + self.backgroundColor = [UIColor colorWithWhite:0.4 alpha:0.5f]; + self.vignetteBackground = NO; + + if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending){ + UIViewController *temp = [UIViewController new]; + self.rootViewController = temp; + } + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(setRotation:) + name:UIApplicationDidChangeStatusBarOrientationNotification + object:nil]; + [self setRotation:nil]; - if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending) { - UIViewController *temp = [UIViewController new]; - self.rootViewController = temp; } + return self; +} - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(setRotation:) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; +- (void)addToMainWindow:(UIView *)view +{ [self setRotation:nil]; - } - return self; + + if ([self.subviews containsObject:view]) return; + + if (self.hidden) + { + _previousKeyWindow = [[[UIApplication sharedApplication] keyWindow] retain]; + self.alpha = 0.0f; + self.hidden = NO; + [self makeKeyWindow]; + } + + // if something's been added to this window, then this window should have interaction + self.userInteractionEnabled = YES; + + if (self.subviews.count > 0) + { + ((UIView*)[self.subviews lastObject]).userInteractionEnabled = NO; + } + + if (_backgroundImage) + { + UIImageView *backgroundView = [[UIImageView alloc] initWithImage:_backgroundImage]; + backgroundView.frame = self.bounds; + backgroundView.contentMode = UIViewContentModeScaleToFill; + [self addSubview:backgroundView]; + [backgroundView release]; + [_backgroundImage release]; + _backgroundImage = nil; + } + + [self addSubview:view]; } -- (void)addToMainWindow:(UIView *)view { - [self setRotation:nil]; - - if ([self.subviews containsObject:view]) return; - - if (self.hidden) { - _previousKeyWindow = [[[UIApplication sharedApplication] keyWindow] retain]; - self.alpha = 0.0f; - self.hidden = NO; - [self makeKeyWindow]; - } - - // if something's been added to this window, then this window should have interaction - self.userInteractionEnabled = YES; - - if (self.subviews.count > 0) { - ((UIView *)[self.subviews lastObject]).userInteractionEnabled = NO; - } - - if (_backgroundImage) { - UIImageView *backgroundView = [[UIImageView alloc] initWithImage:_backgroundImage]; - backgroundView.frame = self.bounds; - backgroundView.contentMode = UIViewContentModeScaleToFill; - [self addSubview:backgroundView]; - [backgroundView release]; - [_backgroundImage release]; - _backgroundImage = nil; - } - - [self addSubview:view]; +- (void)reduceAlphaIfEmpty +{ + NSMutableArray *remainingViews = NSMutableArray.new; + + for (UIView *view in self.subviews) { + if ([view isKindOfClass:[UIImageView class]]) { + // do nothing, this is the background + } + else if (CGRectEqualToRect(view.bounds, self.bounds)) { + // also do nothing, this is a different type of background + } + else { + [remainingViews addObject:view]; + } + } + + + if (remainingViews.count == 1) + { + self.alpha = 0.0f; + self.userInteractionEnabled = NO; + } } -- (void)reduceAlphaIfEmpty { - NSMutableArray *remainingViews = NSMutableArray.new; +- (void)removeView:(UIView *)view +{ + [view removeFromSuperview]; - for (UIView *view in self.subviews) { - if ([view isKindOfClass:[UIImageView class]]) { - // do nothing, this is the background - } else if (CGRectEqualToRect(view.bounds, self.bounds)) { - // also do nothing, this is a different type of background - } else { - [remainingViews addObject:view]; + UIView *topView = [self.subviews lastObject]; + if ([topView isKindOfClass:[UIImageView class]]) + { + // It's a background. Remove it too + [topView removeFromSuperview]; + } + + if (self.subviews.count == 0) + { + self.hidden = YES; + [_previousKeyWindow makeKeyWindow]; + [_previousKeyWindow release]; + _previousKeyWindow = nil; + } + else + { + ((UIView*)[self.subviews lastObject]).userInteractionEnabled = YES; } - } - - if (remainingViews.count == 1) { - self.alpha = 0.0f; - self.userInteractionEnabled = NO; - } } -- (void)removeView:(UIView *)view { - [view removeFromSuperview]; - - UIView *topView = [self.subviews lastObject]; - if ([topView isKindOfClass:[UIImageView class]]) { - // It's a background. Remove it too - [topView removeFromSuperview]; - } - - if (self.subviews.count == 0) { - self.hidden = YES; - [_previousKeyWindow makeKeyWindow]; - [_previousKeyWindow release]; - _previousKeyWindow = nil; - } else { - ((UIView *)[self.subviews lastObject]).userInteractionEnabled = YES; - } +- (void)drawRect:(CGRect)rect +{ + if (_backgroundImage || !_vignetteBackground) return; + CGContextRef context = UIGraphicsGetCurrentContext(); + + size_t locationsCount = 2; + CGFloat locations[2] = {0.0f, 1.0f}; + CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f}; + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount); + CGColorSpaceRelease(colorSpace); + + CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); + float radius = MIN(self.bounds.size.width , self.bounds.size.height) ; + CGContextDrawRadialGradient (context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation); + CGGradientRelease(gradient); } -- (void)drawRect:(CGRect)rect { - if (_backgroundImage || !_vignetteBackground) return; - CGContextRef context = UIGraphicsGetCurrentContext(); - - size_t locationsCount = 2; - CGFloat locations[2] = {0.0f, 1.0f}; - CGFloat colors[8] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f}; - CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount); - CGColorSpaceRelease(colorSpace); - - CGPoint center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2); - float radius = MIN(self.bounds.size.width, self.bounds.size.height); - CGContextDrawRadialGradient(context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation); - CGGradientRelease(gradient); -} + + @end From e95dd0b554e6cb8060080f2acc3a0473bd198e9c Mon Sep 17 00:00:00 2001 From: taymer Date: Thu, 7 May 2015 10:03:28 +0200 Subject: [PATCH 16/32] Orientation issue on ios8 --- .../ToAddToYourProjects/BlockAlertView.m | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index 4b6e52e..269b70a 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -152,10 +152,16 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message { _blocks = [[NSMutableArray alloc] init]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(setupDisplay) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; + if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending){ + // don't register for notification, rotation is handled by iOS on 8+ + } + else { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(setupDisplay) + name:UIApplicationDidChangeStatusBarOrientationNotification + object:nil]; + } + self.titleColor = kAlertViewTitleTextColor; self.textColor = kAlertViewMessageTextColor; if ([self class] == [BlockAlertView class]) [self setupDisplay]; From 4a7608c547d4175a83fb9d6403fababf0dd8ae8f Mon Sep 17 00:00:00 2001 From: taymer Date: Thu, 7 May 2015 10:03:50 +0200 Subject: [PATCH 17/32] Update BlockAlertsAnd-ActionSheets.podspec --- BlockAlertsAnd-ActionSheets.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlockAlertsAnd-ActionSheets.podspec b/BlockAlertsAnd-ActionSheets.podspec index 9d2b05b..e82a996 100644 --- a/BlockAlertsAnd-ActionSheets.podspec +++ b/BlockAlertsAnd-ActionSheets.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "BlockAlertsAnd-ActionSheets" - s.version = "1.0.8" + s.version = "1.0.9" s.summary = 'Beautifully done UIAlertView and UIActionSheet replacements inspired by TweetBot.' s.homepage = "https://github.com/taymer/BlockAlertsAnd-ActionSheets" s.license = 'MIT' From 2a2ef3f004f0ee12b01948d75d73a8c2912404c1 Mon Sep 17 00:00:00 2001 From: taymer Date: Thu, 7 May 2015 13:06:07 +0200 Subject: [PATCH 18/32] Added all in one line buttons and modified colors --- .../ToAddToYourProjects/BlockAlertView.m | 143 ++++++++++-------- 1 file changed, 83 insertions(+), 60 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index 269b70a..c051c75 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -13,7 +13,9 @@ @implementation BlockAlertView @synthesize backgroundImage = _backgroundImage; @synthesize vignetteBackground = _vignetteBackground; @synthesize tintColor = _tintColor; -@synthesize textColor = _textColor, titleColor = _titleColor; +@synthesize textColor = _textColor; +@synthesize messageFont = _messageFont; +@synthesize allButtonInLine = _allButtonInLine; static UIImage *background = nil; static UIImage *backgroundlandscape = nil; @@ -39,11 +41,19 @@ + (void)initialize { } + (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message { - return [[[BlockAlertView alloc] initWithTitle:title message:message] autorelease]; + return [[[BlockAlertView alloc] initWithTitle:title message:message tintColor:nil textColor:nil] autorelease]; +} + ++ (BlockAlertView *)alertWithTitle:(NSString *)title + message:(NSString *)message + tintColor:(UIColor *)tintColor + textColor:(UIColor *)textColor { + return [ + [[BlockAlertView alloc] initWithTitle:title message:message tintColor:tintColor textColor:textColor] autorelease]; } + (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message { - BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:title message:message]; + BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:title message:message tintColor:nil textColor:nil]; [alert setCancelButtonWithTitle:NSLocalizedString(@"Dismiss", nil) block:nil]; [alert show]; [alert release]; @@ -54,7 +64,9 @@ + (void)showErrorAlert:(NSError *)error { initWithTitle:NSLocalizedString(@"Operation Failed", nil) message:[NSString stringWithFormat:NSLocalizedString(@"The operation did not complete successfully: %@", nil), - error]]; + error] + tintColor:nil + textColor:nil]; [alert setCancelButtonWithTitle:@"Dismiss" block:nil]; [alert show]; [alert release]; @@ -74,7 +86,7 @@ - (void)addComponents:(CGRect)frame { labelView.font = titleFont; labelView.numberOfLines = 0; labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = self.titleColor; + labelView.textColor = _textColor ? _textColor : kAlertViewTitleTextColor; labelView.backgroundColor = [UIColor clearColor]; labelView.textAlignment = NSTextAlignmentCenter; labelView.shadowColor = kAlertViewTitleShadowColor; @@ -87,16 +99,16 @@ - (void)addComponents:(CGRect)frame { } if (_message) { - CGSize size = [_message sizeWithFont:messageFont + CGSize size = [_message sizeWithFont:self.messageFont constrainedToSize:CGSizeMake(frame.size.width - kAlertViewBorder * 2, 1000) lineBreakMode:NSLineBreakByWordWrapping]; UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width - kAlertViewBorder * 2, size.height)]; - labelView.font = messageFont; + labelView.font = self.messageFont; labelView.numberOfLines = 0; labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = self.textColor; + labelView.textColor = _textColor ? _textColor : kAlertViewMessageTextColor; labelView.backgroundColor = [UIColor clearColor]; labelView.textAlignment = NSTextAlignmentCenter; labelView.shadowColor = kAlertViewMessageShadowColor; @@ -138,7 +150,10 @@ - (void)setupDisplay { if (_shown) [self show]; } -- (id)initWithTitle:(NSString *)title message:(NSString *)message { +- (id)initWithTitle:(NSString *)title + message:(NSString *)message + tintColor:(UIColor *)tintColor + textColor:(UIColor *)textColor { self = [super init]; if (self) { @@ -152,20 +167,19 @@ - (id)initWithTitle:(NSString *)title message:(NSString *)message { _blocks = [[NSMutableArray alloc] init]; - if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending){ - // don't register for notification, rotation is handled by iOS on 8+ - } - else { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(setupDisplay) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; - } + if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending) { + // don't register for notification, rotation is handled by iOS on 8+ + } else { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(setupDisplay) + name:UIApplicationDidChangeStatusBarOrientationNotification + object:nil]; + } - self.titleColor = kAlertViewTitleTextColor; - self.textColor = kAlertViewMessageTextColor; + self.messageFont = messageFont; if ([self class] == [BlockAlertView class]) [self setupDisplay]; - + _tintColor = [tintColor retain]; + _textColor = [textColor retain]; _vignetteBackground = NO; } @@ -178,6 +192,9 @@ - (void)dealloc { [_backgroundImage release]; [_view release]; [_blocks release]; + [_messageFont release]; + [_tintColor release]; + [_textColor release]; [super dealloc]; } @@ -223,50 +240,56 @@ - (void)show { highlightedImage = [highlightedImage stretchableImageWithLeftCapWidth:(int)(highlightedImage.size.width + 1) >> 1 topCapHeight:0]; - CGFloat maxHalfWidth = floorf((_view.bounds.size.width - kAlertViewBorder * 3) * 0.5); CGFloat width = _view.bounds.size.width - kAlertViewBorder * 2; CGFloat xOffset = kAlertViewBorder; - if (isSecondButton) { - width = maxHalfWidth; - xOffset = width + kAlertViewBorder * 2; - isSecondButton = NO; - } else if (i + 1 < _blocks.count) { - // In this case there's another button. - // Let's check if they fit on the same line. - CGSize size = [title sizeWithFont:buttonFont - minFontSize:10 - actualFontSize:nil - forWidth:_view.bounds.size.width - kAlertViewBorder * 2 - lineBreakMode:NSLineBreakByClipping]; - - if (size.width < maxHalfWidth - kAlertViewBorder) { - // It might fit. Check the next Button - NSArray *block2 = [_blocks objectAtIndex:i + 1]; - NSString *title2 = [block2 objectAtIndex:1]; - size = [title2 sizeWithFont:buttonFont - minFontSize:10 - actualFontSize:nil - forWidth:_view.bounds.size.width - kAlertViewBorder * 2 - lineBreakMode:NSLineBreakByClipping]; + if (_allButtonInLine) { + width = floorf((_view.bounds.size.width - kAlertViewBorder * (_blocks.count + 1)) / _blocks.count); + xOffset = i * width + kAlertViewBorder * (i + 1); + isSecondButton = (i < _blocks.count - 1); + } else { + CGFloat maxHalfWidth = floorf((_view.bounds.size.width - kAlertViewBorder * 3) * 0.5); + if (isSecondButton) { + width = maxHalfWidth; + xOffset = width + kAlertViewBorder * 2; + isSecondButton = NO; + } else if (i + 1 < _blocks.count) { + // In this case there's another button. + // Let's check if they fit on the same line. + CGSize size = [title sizeWithFont:buttonFont + minFontSize:10 + actualFontSize:nil + forWidth:_view.bounds.size.width - kAlertViewBorder * 2 + lineBreakMode:NSLineBreakByClipping]; if (size.width < maxHalfWidth - kAlertViewBorder) { - // They'll fit! - isSecondButton = YES; // For the next iteration - width = maxHalfWidth; + // It might fit. Check the next Button + NSArray *block2 = [_blocks objectAtIndex:i + 1]; + NSString *title2 = [block2 objectAtIndex:1]; + size = [title2 sizeWithFont:buttonFont + minFontSize:10 + actualFontSize:nil + forWidth:_view.bounds.size.width - kAlertViewBorder * 2 + lineBreakMode:NSLineBreakByClipping]; + + if (size.width < maxHalfWidth - kAlertViewBorder) { + // They'll fit! + isSecondButton = YES; // For the next iteration + width = maxHalfWidth; + } + } + } else if (_blocks.count == 1) { + // In this case this is the ony button. We'll size according to the text + CGSize size = [title sizeWithFont:buttonFont + minFontSize:10 + actualFontSize:nil + forWidth:_view.bounds.size.width - kAlertViewBorder * 2 + lineBreakMode:NSLineBreakByClipping]; + + size.width = MAX(size.width, 80); + if (size.width + 2 * kAlertViewBorder < width) { + width = size.width + 2 * kAlertViewBorder; + xOffset = floorf((_view.bounds.size.width - width) * 0.5); } - } - } else if (_blocks.count == 1) { - // In this case this is the ony button. We'll size according to the text - CGSize size = [title sizeWithFont:buttonFont - minFontSize:10 - actualFontSize:nil - forWidth:_view.bounds.size.width - kAlertViewBorder * 2 - lineBreakMode:NSLineBreakByClipping]; - - size.width = MAX(size.width, 80); - if (size.width + 2 * kAlertViewBorder < width) { - width = size.width + 2 * kAlertViewBorder; - xOffset = floorf((_view.bounds.size.width - width) * 0.5); } } From 2fc310e69d024ee531ab0fc7489a0a1ce4c82a29 Mon Sep 17 00:00:00 2001 From: taymer Date: Thu, 7 May 2015 13:07:12 +0200 Subject: [PATCH 19/32] Added all in one line buttons and modified colors --- .../ToAddToYourProjects/BlockAlertView.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h index 011b709..0d3973a 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h @@ -17,10 +17,18 @@ } + (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message; ++ (BlockAlertView *)alertWithTitle:(NSString *)title + message:(NSString *)message + tintColor:(UIColor *)tintColor + textColor:(UIColor *)textColor; + + (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message; + (void)showErrorAlert:(NSError *)error; -- (id)initWithTitle:(NSString *)title message:(NSString *)message; +- (id)initWithTitle:(NSString *)title + message:(NSString *)message + tintColor:(UIColor *)tintColor + textColor:(UIColor *)textColor; - (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block; - (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block; @@ -41,6 +49,7 @@ @property(nonatomic, readwrite) BOOL vignetteBackground; @property(nonatomic, retain) UIColor *tintColor; @property(nonatomic, retain) UIColor *textColor; -@property(nonatomic, retain) UIColor *titleColor; +@property(nonatomic, retain) UIFont *messageFont; +@property(nonatomic) BOOL allButtonInLine; @end From 1dac714987f3d8a9982defc31d93cb09ea411e27 Mon Sep 17 00:00:00 2001 From: taymer Date: Thu, 7 May 2015 13:07:52 +0200 Subject: [PATCH 20/32] Added all in one line buttons and modified colors --- .../ToAddToYourProjects/BlockActionSheet.h | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h index ef160ce..afa6766 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h @@ -9,26 +9,27 @@ * A simple block-enabled API wrapper on top of UIActionSheet. */ @interface BlockActionSheet : NSObject { -@private - UIView *_view; - NSMutableArray *_blocks; - CGFloat _height; + @private + UIView *_view; + NSMutableArray *_blocks; + 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)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; +- (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; - (void)showInView:(UIView *)view; From d8c04920b7e041b537c7470ef92f4052252804e8 Mon Sep 17 00:00:00 2001 From: taymer Date: Thu, 7 May 2015 13:08:16 +0200 Subject: [PATCH 21/32] Added all in one line buttons and modified colors --- .../ToAddToYourProjects/BlockActionSheet.m | 410 +++++++++--------- 1 file changed, 198 insertions(+), 212 deletions(-) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m index 222d48c..543b83b 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m @@ -18,256 +18,242 @@ @implementation BlockActionSheet #pragma mark - init -+ (void)initialize -{ - if (self == [BlockActionSheet class]) - { - background = [UIImage imageNamed:kActionSheetBackground]; - background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kActionSheetBackgroundCapHeight] retain]; - titleFont = [kActionSheetTitleFont retain]; - buttonFont = [kActionSheetButtonFont retain]; - } ++ (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])) - { - UIWindow *parentView = [BlockBackground sharedInstance]; - CGRect frame = parentView.bounds; - - _view = [[UIView alloc] initWithFrame:frame]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - _blocks = [[NSMutableArray alloc] init]; - _height = kActionSheetTopMargin; - - 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)]; - labelView.font = titleFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kActionSheetTitleTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kActionSheetTitleShadowColor; - labelView.shadowOffset = kActionSheetTitleShadowOffset; - labelView.text = title; - - labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + 5; - } - _vignetteBackground = NO; ++ (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; + + _view = [[UIView alloc] initWithFrame:frame]; + + _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; + + _blocks = [[NSMutableArray alloc] init]; + _height = kActionSheetTopMargin; + _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)]; + 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; + labelView.shadowColor = kActionSheetTitleShadowColor; + labelView.shadowOffset = kActionSheetTitleShadowOffset; + labelView.text = title; + + labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; + + [_view addSubview:labelView]; + [labelView release]; + + _height += size.height + 5; } - - return self; + _vignetteBackground = NO; + } + + return self; } -- (void) dealloc -{ - [_view release]; - [_blocks release]; - [super dealloc]; +- (void)dealloc { + [_view release]; + [_blocks release]; + [_tintColor release]; + [super dealloc]; } -- (NSUInteger)buttonCount -{ - return _blocks.count; +- (NSUInteger)buttonCount { + return _blocks.count; } -- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block atIndex:(NSInteger)index -{ - if (index >= 0) - { - [_blocks insertObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil] - atIndex:index]; - } - else - { - [_blocks addObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil]]; - } +- (void)addButtonWithTitle:(NSString *)title color:(NSString *)color block:(void (^)())block atIndex:(NSInteger)index { + if (index >= 0) { + [_blocks + insertObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil] + atIndex:index]; + } else { + [_blocks + addObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil]]; + } } -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; +- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block { + [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; } -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"black" block:block atIndex:-1]; +- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block { + [self addButtonWithTitle:title color:@"black" block:block atIndex:-1]; } -- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"gray" block:block atIndex:-1]; +- (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 -{ - [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; +- (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 -{ - [self addButtonWithTitle:title color:@"black" block:block atIndex:index]; +- (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 -{ - [self addButtonWithTitle:title color:@"gray" block:block atIndex:index]; +- (void)addButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block { + [self addButtonWithTitle:title color:@"gray" block:block atIndex:index]; } -- (void)showInView:(UIView *)view -{ - NSUInteger i = 1; - for (NSArray *block in _blocks) - { - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width)>>1 topCapHeight:0]; - - UIImage *highlightedImage = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button-highlighted.png", color]]; - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width-kActionSheetBorder*2, kActionSheetButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { +- (void)showInView:(UIView *)view { + NSUInteger i = 1; + for (NSArray *block in _blocks) { + NSString *title = [block objectAtIndex:1]; + NSString *color = [block objectAtIndex:2]; + + UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button.png", color]]; + image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width) >> 1 topCapHeight:0]; + + UIImage *highlightedImage = + [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button-highlighted.png", color]]; + + UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; + button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width - kActionSheetBorder * 2, + kActionSheetButtonHeight); + button.titleLabel.font = buttonFont; + if (IOS_LESS_THAN_6) { #pragma clan diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; + button.titleLabel.minimumFontSize = 10; #pragma clan diagnostic pop - } - else { - button.titleLabel.minimumScaleFactor = 0.1; - } - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kActionSheetButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i++; - - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) - { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - } - [button setTitleColor:kActionSheetButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kActionSheetButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - button.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:button]; - _height += kActionSheetButtonHeight + kActionSheetBorder; + } else { + button.titleLabel.minimumScaleFactor = 0.1; } - - UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; - modalBackground.image = background; - modalBackground.contentMode = UIViewContentModeScaleToFill; - modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [_view insertSubview:modalBackground atIndex:0]; - [modalBackground release]; - - [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; - [[BlockBackground sharedInstance] addToMainWindow:_view]; - CGRect frame = _view.frame; - frame.origin.y = [BlockBackground sharedInstance].bounds.size.height; - frame.size.height = _height + kActionSheetBounce; - _view.frame = frame; - - __block CGPoint center = _view.center; - center.y -= _height + kActionSheetBounce; - - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [BlockBackground sharedInstance].alpha = 1.0f; - _view.center = center; - } completion:^(BOOL finished) { - [UIView animateWithDuration:0.1 - delay:0.0 - options:UIViewAnimationOptionAllowUserInteraction - animations:^{ - center.y += kActionSheetBounce; - _view.center = center; - } completion:nil]; - }]; - - [self retain]; -} + button.titleLabel.adjustsFontSizeToFitWidth = YES; + button.titleLabel.textAlignment = NSTextAlignmentCenter; + button.titleLabel.shadowOffset = kActionSheetButtonShadowOffset; + button.backgroundColor = [UIColor clearColor]; + button.tag = i++; -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated -{ - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) - { - id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) - { - ((void (^)())obj)(); - } + [button setBackgroundImage:image forState:UIControlStateNormal]; + if (highlightedImage) { + [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; } - - if (animated) - { - CGPoint center = _view.center; - center.y += _view.bounds.size.height; - [UIView animateWithDuration:0.4 + [button setTitleColor:kActionSheetButtonTextColor forState:UIControlStateNormal]; + [button setTitleShadowColor:kActionSheetButtonShadowColor forState:UIControlStateNormal]; + [button setTitle:title forState:UIControlStateNormal]; + button.accessibilityLabel = title; + + [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; + + button.autoresizingMask = UIViewAutoresizingFlexibleWidth; + + [_view addSubview:button]; + _height += kActionSheetButtonHeight + kActionSheetBorder; + } + + UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; + modalBackground.image = background; + if (_tintColor) { + modalBackground.image = [modalBackground.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; + modalBackground.tintColor = _tintColor; + } + modalBackground.contentMode = UIViewContentModeScaleToFill; + modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [_view insertSubview:modalBackground atIndex:0]; + [modalBackground release]; + + [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; + [[BlockBackground sharedInstance] addToMainWindow:_view]; + CGRect frame = _view.frame; + frame.origin.y = [BlockBackground sharedInstance].bounds.size.height; + frame.size.height = _height + kActionSheetBounce; + _view.frame = frame; + + __block CGPoint center = _view.center; + center.y -= _height + kActionSheetBounce; + + [UIView animateWithDuration:0.4 + delay:0.0 + options:UIViewAnimationOptionCurveEaseOut + animations:^{ + [BlockBackground sharedInstance].alpha = 1.0f; + _view.center = center; + } + completion:^(BOOL finished) { + [UIView animateWithDuration:0.1 delay:0.0 - options:UIViewAnimationOptionCurveEaseIn + options:UIViewAnimationOptionAllowUserInteraction animations:^{ - _view.center = center; - [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; - } completion:^(BOOL finished) { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; - }]; - } - else - { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; + center.y += kActionSheetBounce; + _view.center = center; + } + completion:nil]; + }]; + + [self retain]; +} + +- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { + if (buttonIndex >= 0 && buttonIndex < [_blocks count]) { + id obj = [[_blocks objectAtIndex:buttonIndex] objectAtIndex:0]; + if (![obj isEqual:[NSNull null]]) { + ((void (^)())obj)(); } + } + + if (animated) { + CGPoint center = _view.center; + center.y += _view.bounds.size.height; + [UIView animateWithDuration:0.4 + delay:0.0 + options:UIViewAnimationOptionCurveEaseIn + animations:^{ + _view.center = center; + [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; + } + completion:^(BOOL finished) { + [[BlockBackground sharedInstance] removeView:_view]; + [_view release]; + _view = nil; + [self autorelease]; + }]; + } else { + [[BlockBackground sharedInstance] removeView:_view]; + [_view release]; + _view = nil; + [self autorelease]; + } } #pragma mark - Action -- (void)buttonClicked:(id)sender -{ - /* Run the button's block */ - int buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; +- (void)buttonClicked:(id)sender { + /* Run the button's block */ + int buttonIndex = [(UIButton *)sender tag] - 1; + [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; } @end From ccbfd6464691863bc594fe235906202c751ed39f Mon Sep 17 00:00:00 2001 From: Pedro Ventura Date: Mon, 11 May 2015 15:43:44 +0200 Subject: [PATCH 22/32] No Requires ARC --- BlockAlertsAnd-ActionSheets.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/BlockAlertsAnd-ActionSheets.podspec b/BlockAlertsAnd-ActionSheets.podspec index 0debc6c..557a079 100644 --- a/BlockAlertsAnd-ActionSheets.podspec +++ b/BlockAlertsAnd-ActionSheets.podspec @@ -13,5 +13,6 @@ Pod::Spec.new do |s| s.subspec 'TableAlertView' do |table| table.source_files = "BlockAlertsDemo/ToAddToYourProjects/BlockTableAlertView.{h,m}" end + s.requires_arc = false end From a9b5205b71ad3d6c845005b1f2d0af99247c4d7e Mon Sep 17 00:00:00 2001 From: Taymer Ragazzini Date: Fri, 29 May 2015 11:28:49 +0200 Subject: [PATCH 23/32] new file: alert-blue-button.png new file: alert-blue-button@2x.png --- .../images/AlertView/alert-blue-button.png | Bin 0 -> 735 bytes .../images/AlertView/alert-blue-button@2x.png | Bin 0 -> 1263 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 BlockAlertsDemo/images/AlertView/alert-blue-button.png create mode 100644 BlockAlertsDemo/images/AlertView/alert-blue-button@2x.png diff --git a/BlockAlertsDemo/images/AlertView/alert-blue-button.png b/BlockAlertsDemo/images/AlertView/alert-blue-button.png new file mode 100644 index 0000000000000000000000000000000000000000..d2ddbc779182bc67d074e1c1e037ba5278df8f7f GIT binary patch literal 735 zcmV<50wDc~P)<}010qNS#tmY3ljhU3ljkVnw%H_000McNliru-vu2B8zrdBAUXg50&Gb{ zK~z}7&6vGz)KCzGziWGe4V!EN2%#VaNP$o&C{U16MdAf0d5Eoe51s@Xo`4R5fF=zR z6yc``0!3t#O|n^E&kTj_ti4KW-;8v%%}R50&bjA~2kJEd-T@=P8a$(-&!F1e6~8gC z70=&TpI>`Q=h`wZxkOWCS&IL+%jnBnWVH7Q*Z`yi^P{`^WTkh1!}-I%=wu8gje)_% zM3=jC7H)F%ZOg_xAAbRNW8g*S`km+V4>w)9_Y?Cen9^vOVwp!y_UYb!;Qa8`3`ivdTSYR%j0z?i zOeU&e%%ljqK%TLhXEZ37GVya}vJBI3GFg_*FoS}HF>sxkzy_YlnG56@RIrdT)vmS% zWCqLoPi4vqbfFAfeJDlF&;@y#B$p|w4PJyHrmUP9Kfxpo=NUhlf>BdYz*(5fR9x){ zz?p>sk~h!$*M_T*(^U-&E|6d9AGR~hT!gXH3^NNAc~}ih;g@hxQ}aw%m1>~}a;96D zk_&2JtTa&=3zvDDOrPC+XCaL$mB|SLOoBF1U^#ny^sc0@c>5=ux&mC7geV9 zmJWc6@;xGKN5CsN9^&Gp{j4#=#R+me1bAKE<(;V8zZcK-G08x+VFNjcq8!M{0XjbT z4y=}7mVq}e?ySdGm-2<}010qNS#tmY3ljhU3ljkVnw%H_000McNliru-vu2B8wl+ad`|!X1bj(E zK~#9!?VQhRBt;a*KULk+NhX_Q6E|iTB})w1qwcOCi;#Tv`92rRo2G{1HxGqY9oJXH70>|}Z;6J%kg>OnJ1&CpO^zTfYA zud2HgkB>#*4PYI(0$c?WMl&pM8@L1f2z&|bipbD6+5}|GuT2r5-=+Eh@)GbN@Cqoh z#pjr~v_>*LPddAZQfegWA|jZ>U2JWS=DlrNyT9ky@E!2Ji2U6B|K3@?27Cper{^K4!eEqxl%9JEolSz$ z)c@F`zI_YeU*LHWxvTSkegrIJOKVhDt|6w0t?glsc0nA7jM?QdN8WG5G^ws!BU@Sn zSO7jK7_$ug1)BNwx6x^ed)UC%4hSKV={a;|64z|7ck6S&0bJI=20*s7>OnCLY;8Y) zOzkgQ+sBy(dSa4nX|=#>L+8aC*@b1CX@YeG7uF%RMRsAi7+Ft&>z-2Q!8vTRK89vH z0GDQsM4cm@Sty2Xq`)Nrl~lYjIm21Xyu2AD#0O3XCmX=pfP|Mfzy-NpSwsiAR%8dJ;KebOR%~zC>J@N^+%)k-#Y!c?4VxBMf2_NF+`7v>H1XZx>%11R7!C@W@wKg@H(ax7#BEWTr}Td z({* }GUk6_O#59&6(%k{?|Mcl zMJYw|jf{CBjFGsq85wgLWMZ#W5)qhzO=J1p0r*Trc1|2Zs;ADA zOwDxay)k7@!4&Wka>x77bqHwz*%7b}yeXyu0=km5_2)Gxqo2l=My08rPhOVT`XR2- zR?1t&fyceMc@uayhm>??0hMOs*)p0I=4cP3t%#c<@?P Date: Fri, 29 May 2015 11:30:21 +0200 Subject: [PATCH 24/32] version increment --- BlockAlertsAnd-ActionSheets.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlockAlertsAnd-ActionSheets.podspec b/BlockAlertsAnd-ActionSheets.podspec index e82a996..bc3e7b3 100644 --- a/BlockAlertsAnd-ActionSheets.podspec +++ b/BlockAlertsAnd-ActionSheets.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "BlockAlertsAnd-ActionSheets" - s.version = "1.0.9" + s.version = "1.0.10" s.summary = 'Beautifully done UIAlertView and UIActionSheet replacements inspired by TweetBot.' s.homepage = "https://github.com/taymer/BlockAlertsAnd-ActionSheets" s.license = 'MIT' From 0ee799d67012b577323d7c8964e627e68a7773cf Mon Sep 17 00:00:00 2001 From: Taymer Ragazzini Date: Fri, 29 May 2015 12:19:35 +0200 Subject: [PATCH 25/32] Changed blue tone --- .../images/AlertView/alert-blue-button.png | Bin 735 -> 1299 bytes .../images/AlertView/alert-blue-button@2x.png | Bin 1263 -> 3367 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/BlockAlertsDemo/images/AlertView/alert-blue-button.png b/BlockAlertsDemo/images/AlertView/alert-blue-button.png index d2ddbc779182bc67d074e1c1e037ba5278df8f7f..0ad83b3ebf86ed3b8a9e0dd22d54fc56346712e6 100644 GIT binary patch delta 1243 zcmV<11SI?41(OPpDhVn8VF0a@K=PQ8Ga`R9J3!whGynhuph-kQR9M5!n9plnMHI(B zXYPGTQxj7`5_BO++zF;F*oC;O;MTqV2^F=AZWI?TTosWD{smGOg5c7PyNW2SZ38Zw zS_(x`TZ3s*oBPgjF+c8^n`d1muNN-&y}2`IzVkib^PPE5PMlaLU)Qc}oB`ehUIc&U zIk;;Z_!;=z%s$JFa`NOlSFdh73w$lj=v4E>Q%E}l5)KZEDb_t?eE%Lc-n$IEZf18{ z5P(ZzZgI6ax`>TCR$u!NFfd844KcwaHpgZ3v2(Ln{9>*xf64DaFpSM_KA=7J4C9@x zmvndQ60jz~+tMDn&@L{s^6GnK4zqtU7V`l;3JfGpYYCP(026TUYrFaFM|4}iVcmmw z8{p%1;pyjAPQM>9t72vd8mCZAXf#c#>9cD$OSi@w#Y_>+{d}Kv6Q9RcUt#O^59mMJ z3oUS5Ml)a?W)gu&d}fC5>4{0}*J%toNO_n!0_zZnXM8jRaJ&WPLo>p(E5U#IAi1~W zSRNtFJVSokf22nQRV!%?%?Mz=C6RBclhuh=Vg@8m;7;hepMjdR2r?Feq#;%m*A_Ms zGcq8+TvSQJl1xhwKd+V;u|Fa;S^0CtwA5hGF~*=QsmU-K0-Qh~V5zhEWk?e*FuiFY6@`$uYOa|g99`AC|`<*V|X35vAb z$!aIGVp!tpVNeCu159aZU_4H-tTrv{2bg*>B@57j8|SfF3$LW#*?6zQ#)AQ~jzUNF z1s^O^<2a8KMpnexg4c(yOPwHgf3-yinHfiAHcA8&X|(|q!uvRRh^2{+W32cuJmmuL z+VajT1}YPnF_C0?F!6st;K`ZAssRS%ecex_9Y?i&dhjhe^)ijy~9Y?i`luGG~Df`RdoRfee){hY>rKaTs z(wk#ExYZQPXtp*z#Hzi>oaD_k9k{fZTj`okY~qgy30Nw$es_O&X_7RjxfDcZnue`k zul~=;>A-#}&>VfzS5ph2nHm_Rb)p;@gwYXt;T+x_Mn@QL-vhW3 zfUkCcxz1>Dx!)EJ1xPg7(c&^YH-7^7GMqj8)+c*^-nw=F#ub}gS|iNOLr5Ars5`WT zxp`)n*0_J;itXLKeap-~ZJVY6cz$>D$L}BhzIkflh0{mOF0I5rrVmOd-9z^7-r??d z7a9Nk$7SGU06BN=ozm(2`3q-&H-Pm+_`7}s_`?5P|1Xy#f*(5T*v9|>002ovPDHLk FV1irbOkV&1 delta 675 zcmV;U0$lx*3f~2gDhU|?IRIuG*i`@nZ;sq#qh^=@Jo&*}6fDVFyCJho4;im`!MP!prvRPlx z42A8iy-I7}jC8flN^^A1x#x}t>NNn~0VBW~Jfot|pxWFOzcH{C&)-;|UwcaD+A@DG zxkOWCS&IL+%jnBnWVH7Q*Z`yi^P{`^WTkh1!}-I%=wu8gje)_%M3=jC7H)F%ZOg_x zAAbRNW8g*S`km+V4>w)9_Y?Cen9^vOVwp!y_UYb!;Qa8 znrAd9m@@HmX0i;^a57nz%`k(4g)wlQnZO2~$(ak}8C0;4GS#lO24n`y`%iym$_jL$ z3|xIEMb6L#d731bDXI-#gdwJ^oEbmCBn{^oKbeA2Q&7NJn9EdL?Fhh`g#nT`&->Sg ztB})G4Gb=jU+N#WGt69svC|AQ3l(`-4NT#ea8Xn9Ojwm_p$BrNTbPmyYGAB1Q5XxC zd7Dh1@t~iS)mPgBbJOg%T|26>L)6Tm712gOT|4W$YgAorbb{+r#002ov JPDHLkV1gNPIOzZY diff --git a/BlockAlertsDemo/images/AlertView/alert-blue-button@2x.png b/BlockAlertsDemo/images/AlertView/alert-blue-button@2x.png index aa2b4eeb17cba8c95be3f83f77ec8f15b9dd4c19..78d332e3462ddf483e9fa45b8227cf3280518e18 100644 GIT binary patch delta 3327 zcmV$R~23R z+*kkZ>P})~LW5$`?NCL*fe^%~plB4ufjSUJIuZ}XqWNMh(m1`P6X0N)4j0079^7Q)6B zBupTa^<(WWoF0I2hIsQDcz8WuehR=3NIs>Xl>smLR)1%L$;ms9y)ot)X}Wg>;9 zW0KzN<}SMJljipM2Y-K*ysv+aAOr#mAOx81NqHwdD*}*!0Hi=v8~uyY zKP%}PQ@81s)PJNV(*tE_H19DtRT{GGz3{|$w0SVQwugA*YQFGglE2i3ISb(L0PYN1 zr_pVlEU%vX{G-m+Qaa58pu3K2v|>V_nuOL}(`1SP)04wd-e0Apd#pw-b`yWoMQ?m4 zqo>aczj>(qdv<*f@%mc;@Fsu{ko;fn{U-pvDQnx9oV=^=Ge(?y@X@-cYQO>x8jHm! z*{filrST{KwDW*Gsp2hEchZt*XVZ<)4~?~N^~}XzKLiN@05IKq13bJ206!!74FT{T z0RILAlT&v?x(NW_zRx~loj`x}RJ}T{p!SoYaV4J;G5!T*7&ya-GM_lVtaF!kh(a(~ zOj7ukk>!w5Z(REAcl-8cQ%v7}CAa+E4#3v|d`{MP&~5JYM)}OcX|*>m1?T77*E`DHBfz30h~>N z*&zU2oFwvwu)YNZN%M^fP+Ql`_$QF+2`KQ87A*yx)Mx6_O2yDJXsKAECnsV|0EJc6 zQ>ex%#>y#yU^QUcCZfs_jdpu2Jo(K>lCExaPOyo2r6$O3CRG)ywXgoK?e)0 zv&)thZPoN12}sO--S>Z^R=ya4*$bj+qwgacPX>|3={(pxt5%lvxjW8%0#{!ABS0YD zdN6d28TnhdDDLPvPv zb7E?ZY`p$@RGdyvre-&25AgXoXP873dvclE$=L{IWFoW?P34I)&Wr~QPuySp*qi0fUBNG*&HL(KY6o z1r<1J_)MuAX3?bvcM7DESaUYiK|#3X)k#6O0pnrXA9H`0(IuO6_>z&$WyeMTuG8t?19r-Wrny+W6bdZe~qgIW)PVuu#3f>FvA zI=-7JhqPtvcvc$7EQ7|SOWB2sM-3sB41(#pa&s!=&S6IJNL|ycs5p!YCzQ6s=6x7W zWo!_2!Wc4480IlvX~EFS7kMNDXimpy(lJC*NkD%UF3D32k4c^qv)z*WCnIInoLxg> zhG-CrsgLBf1!w5AuCOSS7)xaeM?MXL8*V|zmMfbjqO4kj`Eeu@@-3FvD^ptei>NhqkS$c`g7AWxO1Il{t= z#=|N})C?1jSQ1dNS;uq>$&0Smi$i-4Dr03XLz-;R8#$_act|9VHbv{Oh1XtaBvUG3 z)qCGq$u!Pf zeXG7Gm}i>7tkjfEG_fn~-8mT8yq#K|*IrsoO6)9wpUYrM{|a zULkr~$QlTZag5=Jisxlctv{%mi17N04}#cw+!*hn=RQUdRr-!J``KpWL}^AMOvYP) zF}2NDaU@pG!e-^w>Z;UiD)3Ty$3{!6oF!V7u&8s@;FjH{Je8j@yOq(7O(}mBc3T() z;H5bv;0==p;j3#pZ5pOTX`l0`otqQ8&Cz?8Rppp<9kDwHinAt}p_e)tt29AzmG+4K zOotP7;kZD-i?Ly~B~K?INYsRdZqkN#iB+E+VD<0QsSGLi8%z`ElC;*)-s=ZuJ>gKx$d%76wl#$%{5gLuzqb2cefV4>cDbg7)4yJUZ&%jVP+m0VdK z)VfLHGQt5NK#p1~MJrUvh|W^gk!UJty8Y(5AKvaWWusPwjm<^}wPwqKJyO=QF^ z`%$skU`d6rjBZA%k{}G6ESRI-=~a|@>+zum49r~~1q8aJ(BP`we&cSzS0 z%$|DLH}~_Ow-f1EuFrpf!gkwJ90`nOf4O2pt!?sVd~|iOn{d`}gyyJPRE*cwp{=CF zM%$yy4)Z)F9b08VL>oI=r|o0hYO@9-#8>4bRW+bQZF{r7RnO7*5YONm)p%>I zB_sPL908dybTOZxlFaUu6+9_36ko4AYgVz`E;+wM6)H5kbhBZ~e!)r_ruATfV!v4n zD<`SyNv?99FC~I}Xldy02~@i7hw|1d&te%rVSQ@^V}jH(CQJCq^B=&NEUq+a00NoO%>n=dLbsW5YIbV4?0C*Ar4qm;4IGrL)Hqq^zULJ4RIgK#c zM7((e2d`erhIujoxD4QNAY%Xd3y`%x>z{7xB*OYOWNj1sm!3g7%=lB1 zmzysk-9G;@Y`^cr03+hT4NTv81M?0FA6NQ6IdOj%!ulp40oPu74%aST0MwU|X4z^F zz&`+d?eNY2ARZoI?XI&3Ya0lgC(x~L_Ge;eGewV&+fP7P-^OI;G`j862x}W4XW0Me z1zdmW&)H&MCHa@30^kb(egyzw>kjOG@KczadiQOKx6`*@#nr$44)OYxeCdlMpO{w} zeH3fJBLE%%1nXz+#l}77(e2!U$?lnBD}9p0^y+Jv?O(yomoMVrwHGr)`~krCNIrAa zwpL%JKId}=_3QWF58y-a2V#%UX9nP}0G?0W?dJeq8~ghG{{yD(RmP57bRhr$002ov JPDHLkV1gR!PAmWb delta 1207 zcmV;o1W5a*8t(~^DhU|?IRIuG*i`RCwC$oX=|{MHI(B zRo&A`CYxjvH)acob2DMFhj@ zaRdGcEV~jkzjh`wvsLvxRQJs6WO^qPWMQW2K{HIv&`@8#-|u^`s=E}Ak44}OU>$$B z0$c?WMl&pM8@L1f2z&|bipbD6+5}|GuT2r5-=+Eh@)GbN@Cqoh#pjr~v_>*LPddAZ zQfegWA|jZ>U2JWS=DlrNyT9ky@E!2Ji2U6B|K3@?27Cper{mUx-YG5AxGs0k$gOr|o3Y|@Y($xRhqP~3#;9uZ* z5xJ}Le|`ikWJ_yQSFRzZiLLEnj&?yDh>Y3gFh|~R#5Ad{Tq9dr16Tk)C>VdU4EzO} z`SrKaX^MN;z}5~3A(H7ibY&9PY_NChbHD*y*1!fpwzTR&F%4{OKY&c_FI(HknFe}d zl5AaQ@PXN0Ux^5;G4(_MKefBxr8L(0!c?4VxBMf2_NF+`7v>H1XZx>%11R7!C@W@wKg@H(ax7#BEWTr}Td({7f+rNFqrJtnTl3@fFWmHGqY0;hPh*%>rSciKm&jG0L13cps4`2Px3j7 zHO0tX4Q%;A|6GjHNqD&Ab1pCdwi4iJU;`AoGL`oYHZWi`2-xEz@ZfyXbwHpZox6xi zd$JoWB-J%XKX(E6Ohk50973w6&XY{dbn3k^ zWlq5q@Dg&z`_O-N2x$S?5wH!sDW(Aex{|f^=QSv!pT?C&rKz7!UY6MUA+FI@%3H;O z$Gy3E6L>d=lyqhRm1g7FGMX0VXb+^Vh?^qvUh$>ZNWKBS_lE3NT(jn-r0^#Tj=1lL zX(6WNS#o?pzHIjc@Q#RleA@fO!_*%W7wH_ozY4rK;tC`B1^5$x{Qeif{j!%z{sTn7 VUe#|iiVFY$002ovPDHLkV1o0;L7D&n From 72f780605ec26358c91ad7c0843a07ccb123a4f3 Mon Sep 17 00:00:00 2001 From: Taymer Ragazzini Date: Fri, 29 May 2015 13:29:01 +0200 Subject: [PATCH 26/32] Added blue color for actionsheet --- .../images/ActionSheet/action-blue-button.png | Bin 0 -> 1105 bytes .../images/ActionSheet/action-blue-button@2x.png | Bin 0 -> 1870 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 BlockAlertsDemo/images/ActionSheet/action-blue-button.png create mode 100644 BlockAlertsDemo/images/ActionSheet/action-blue-button@2x.png diff --git a/BlockAlertsDemo/images/ActionSheet/action-blue-button.png b/BlockAlertsDemo/images/ActionSheet/action-blue-button.png new file mode 100644 index 0000000000000000000000000000000000000000..0ef70978c01b9afa558ffbd38264ea5ed858975e GIT binary patch literal 1105 zcmV-X1g`suP)T3W11KvqQ zK~z}7#hFcLTxAr7pYz?DNfVPa)Kb%gYP&Jf)`F}06L2AFwLyhaTvkx%vR$}vC%Dmt zi@H=S=++{1;ZK!pgl=>rlwz_G8e`I!rXlGhGnxDS92fV_WG2Z>U3Bg}@NH%;oOjOq zp7)%&pQtMJIQ-;f#J=H=fVY98z#!d?GH@HXMpFLx&g`$Q{)N!Mvsgfn|G2^Y&FhGmIzykvh)hXF-~Q1P96SCTf6Xl-1OyP%EoFH& zHY=1jw>WnEdDd6vDKE_;fWlOa>Np~(cZ`m|z|!4&s87%w#lLiSg|UejnOV4nm0bY5)_!SqmD- zJv88~ZDA^I>Jv2h^hnO&RI~1vy?{Xo39246Z? zublDDCp2gQOzJLlrdfc&+rlcA=5Avb+kZrgFxk+dD^*bq#dM|W1G=(^YVDCT-X%gU zNc^2DrgfeR806YXV+3E!c9G@oEdDON5Bon`YzOBL6c??zjfmL#RPfFsCeGhqO`PU# zc)eH?mHOxE&Tp%0m^gb`t0AYOm^j8(*BZ_rmHOw*;Lz~2X6@>e3bwLN)Z5>vTxz-x z|I{lL_4Z>c>-eOSt=P)o(Ee$;HlvSUI5#zCOrwyPxI|C?Fs7#$>5{1_O0YF-Wi4B) zHQTzBFRy<8MEur7GJoaevloA#{`PYd#p(X-6KeODvq!sSAK6cq?Hs{7PQCKZ#WyGT zyM8k=aQ1_5-n;Sh)yqbTxfuxxldqk-^xbFYuK*je?H_*V*1yqH@4kQO!s6oMt3IiY zb=%X#L`0>&h0)Q`U%vk8@)su_^D_|Lho-wE0OwWWNJfA@Aj)CQP{0FK=XEKLqygqX X#D$Ccoieju00000NkvXXu0mjf5RDmP literal 0 HcmV?d00001 diff --git a/BlockAlertsDemo/images/ActionSheet/action-blue-button@2x.png b/BlockAlertsDemo/images/ActionSheet/action-blue-button@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..5642fd7737cefbad8e56ce2afc2c5d90a62357b2 GIT binary patch literal 1870 zcmV-U2eJ5xP)h2le>#8MDJ z1W_tJiii(BsGy=Kh~`15R-u+ELYt^fMO!u6l(uwl+3UE; zWT^IJDqZkAh|B~m+_~+35c)EJ4bWqphLX>fMvi>c5U^xV|CJ#0eE^%?eD#LPyR9tpX+Q zo(#gnZ^A(j$Y&{C#p94xx3>2q86S?Nv6nxe816^gjqfKb!_@lB$|o z+Ocl)W4LlvG*H6&>p}s49D5h#+(l2dxk^*=q0ym%kH&%Z-a8CngCDF_T|2O$cN0R4 zKuCp(BXK!bfm1HP&zAgO2O$K!DT);>7A#J|D1j{$P7fZ(h2gJef_8dz@Ut$mrhC^N zAoPfzx;pyqL)XS`NCgxt0v9i(0LXyoi=usH8zL41CBX2hpK$KPr!%Q+8*5&@;VA%H zyrY`}Bm1vG|#5=l?9yu{xkHX$a0mQv5L_FDraz#K$1zm=a3gwDG zJlW;vJ>y&{74kaRYF-IjC=~M9YQOsw6SSy<1tNki~5cfNnhb#bq6wb1<4)Yzg zxD~d1vB38kMhP4t;gt}ATOA2FLV`2eI50=Z84J`P4|nd30P{+#IxWkFfz{%cl0w&h zSYyCyOHr4A@7LyOSYg4b8y8t&wWX+=!e$FWe1`C+X_l0;^f%0CXv}IWbjy}&jrI9ekbxDK1 zc0O#O-3slB?|H{CVQXnG+G$tyQwA3 zFu)A3|8oq}^$T62u%+^0rud#KFmrB2gE7pU?le#13S(SN&|j3GZ_ceS3NuU609($b zk<#>9BV}6DOPeK)({FG|nk#b6l3e5^smvwJ4b_sSfjH+SIj$_7wk4gIt85&Y+ejlC zg}LfnXKEr+LWt)HV6~HDDdYMqx9VK|P7Ef5*p#r)m{(erc1goTO6%u7CE*bk8sprG zo~byMo2DM>l*hos%^;M4a%&R6fT9Y80m$(kp2}n18PbZLq2WZwNx$r97jtefq}&QF zEN;00-!A5Sok2L!agwfBck|cN>_b(GPI+ts8f9QsByg~p6#=2lh2^TtV_VWhXWuu( zcI4WtH$QsRDUDs_xAAQ#+yWk{-zrfFd)ZzsLKz2P^`~Y!#VqVn&a*^PN`Z%)|2%u_ zy)7I-Hrcc5^^qSwJfxJG@FGgO(CktU!Y;y!t#IFnun-svEq`Y(Y*g}>>py%CbtQXt zy$&Etlu~eny5ZU_kH1?fr29P0>Lj%>D*_gZcz#OD36c~Jgk6NF6nzWt8Z0ZC82tU{ zJ9{`IKi5pwx!rpYyzs#rFT5q4N?V=Mrl?I+ro2f&yA(B8lv}CYdk;Jh;GAnbI3uZ7 zp6orfe#icUH6uGMQz$v{6C_9;bE?gq5Mr<2vH##JPxcOTMpD3}8xS}`H38__dGPC7 ze*5aRSEW;l>sCunQC4>Sj{VOZKD7ON0K=S-a-EH@{^88wL)(Ac_wiY5m4J^kXI!-uy22;fW&R-MA!^eR*ffNKEoTlc-ab9C_Y{Z6^ise`(BQ*QnhDtZ7?4`Q8XB7K Date: Fri, 29 May 2015 13:37:42 +0200 Subject: [PATCH 27/32] Colored actionbutton --- BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h | 1 + 1 file changed, 1 insertion(+) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h index afa6766..6bdbd58 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h @@ -26,6 +26,7 @@ - (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; - (void)setCancelButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block; - (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block; From 4da5ac2eb6aa496ff579103e593b36e7ff57b320 Mon Sep 17 00:00:00 2001 From: taymer Date: Thu, 18 Feb 2016 13:03:51 +0100 Subject: [PATCH 28/32] Update BlockAlertView.h Added missing initWithTitle --- BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h index 0d3973a..efe384f 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h @@ -25,6 +25,8 @@ + (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message; + (void)showErrorAlert:(NSError *)error; +- (id)initWithTitle:(NSString *)title message:(NSString *)message; + - (id)initWithTitle:(NSString *)title message:(NSString *)message tintColor:(UIColor *)tintColor From 1a0d3de261d15edb8dac76e2639a0114b6f48d12 Mon Sep 17 00:00:00 2001 From: taymer Date: Thu, 18 Feb 2016 13:04:50 +0100 Subject: [PATCH 29/32] Update BlockAlertView.m Added missing initWithTitle --- BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index c051c75..c7fa8b0 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -150,6 +150,10 @@ - (void)setupDisplay { if (_shown) [self show]; } +- (id)initWithTitle:(NSString *)title message:(NSString *)message { + return [self initWithTitle:title message:message tintColor:nil textColor:nil]; +} + - (id)initWithTitle:(NSString *)title message:(NSString *)message tintColor:(UIColor *)tintColor From 111301187903f7428f6cbcc23db28b269c4ede51 Mon Sep 17 00:00:00 2001 From: taymer Date: Wed, 9 Nov 2016 09:02:10 +0100 Subject: [PATCH 30/32] Update BlockAlertsAnd-ActionSheets.podspec --- BlockAlertsAnd-ActionSheets.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlockAlertsAnd-ActionSheets.podspec b/BlockAlertsAnd-ActionSheets.podspec index bc3e7b3..2f14e86 100644 --- a/BlockAlertsAnd-ActionSheets.podspec +++ b/BlockAlertsAnd-ActionSheets.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.author = { 'Gustavo Ambrozio' => '', "Barrett Jacobsen" => "admin@barrettj.com", "Jose Santiago Jr" => '', 'Taymer Ragazzini' => 'tragazzini@gmail.com' } s.source = { :git => 'https://github.com/taymer/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| From d8ead6b6880d4eed274141ca3e62b422d709265a Mon Sep 17 00:00:00 2001 From: Pedro Ventura Date: Fri, 16 Dec 2016 09:16:25 +0100 Subject: [PATCH 31/32] Merges adjustments --- .../ToAddToYourProjects/BlockActionSheet.h | 4 - .../BlockActionSheet.h.orig | 69 -- .../ToAddToYourProjects/BlockActionSheet.m | 123 +-- .../BlockActionSheet.m.orig | 517 ----------- .../BlockActionSheet_BACKUP_1091.m | 517 ----------- .../BlockActionSheet_BASE_1091.m | 273 ------ .../BlockActionSheet_LOCAL_1091.m | 362 -------- .../BlockActionSheet_REMOTE_1091.m | 259 ------ .../ToAddToYourProjects/BlockAlertView.h | 2 +- .../ToAddToYourProjects/BlockAlertView.h.orig | 78 -- .../ToAddToYourProjects/BlockAlertView.m | 306 +++---- .../ToAddToYourProjects/BlockAlertView.m.orig | 865 ------------------ 12 files changed, 196 insertions(+), 3179 deletions(-) delete mode 100755 BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h.orig delete mode 100755 BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m.orig delete mode 100755 BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_BACKUP_1091.m delete mode 100644 BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_BASE_1091.m delete mode 100644 BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_LOCAL_1091.m delete mode 100644 BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_REMOTE_1091.m delete mode 100755 BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h.orig delete mode 100755 BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m.orig diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h index cde51bc..d8284d5 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h @@ -29,10 +29,6 @@ - (void)addButtonWithTitle:(NSString *)title block:(void (^)())block; - (void)addButtonWithTitle:(NSString *)title color:(NSString *)color block:(void (^)())block atIndex:(NSInteger)index; -- (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 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; diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h.orig b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h.orig deleted file mode 100755 index 4d8a79a..0000000 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.h.orig +++ /dev/null @@ -1,69 +0,0 @@ -// -// BlockActionSheet.h -// -// - -#import - -/** - * A simple block-enabled API wrapper on top of UIActionSheet. - */ -@interface BlockActionSheet : NSObject { -<<<<<<< HEAD -@private - UIView *_view; - NSMutableArray *_blocks; - NSMutableArray *_completionBlocks; - CGFloat _height; -======= - @private - UIView *_view; - NSMutableArray *_blocks; - CGFloat _height; - UIColor *_tintColor; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -@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; - -- (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; - -<<<<<<< HEAD -// Add buttons with block -- (void)setCancelButtonWithTitle:(NSString *) title block:(void (^)()) block; -- (void)setDestructiveButtonWithTitle:(NSString *) title block:(void (^)()) block; -- (void)addButtonWithTitle:(NSString *) title block:(void (^)()) block; - -// 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; -======= -- (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; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - -// 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; - -@end diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m index 4071ee6..fc1bc16 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m @@ -19,25 +19,24 @@ @implementation BlockActionSheet #pragma mark - init + (void)initialize { - if (self == [BlockActionSheet class]) { - background = [UIImage imageNamed:kActionSheetBackground]; - background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kActionSheetBackgroundCapHeight] retain]; - titleFont = [kActionSheetTitleFont retain]; - buttonFont = [kActionSheetButtonFont retain]; - } + 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 tintColor:nil textColor:nil] autorelease]; + return [[[BlockActionSheet alloc] initWithTitle:title tintColor:nil textColor:nil] autorelease]; } + (id)sheetWithTitle:(NSString *)title tintColor:(UIColor *)tintColor textColor:(UIColor *)textColor { - return [[[BlockActionSheet alloc] initWithTitle:title tintColor:tintColor textColor:textColor] autorelease]; + return [[[BlockActionSheet alloc] initWithTitle:title tintColor:tintColor textColor:textColor] autorelease]; } -- (id)initWithTitle:(NSString *)title -{ - if ((self = [super init])) - { + +- (id)initWithTitle:(NSString *)title tintColor:(UIColor *)tintColor textColor:(UIColor *)textColor { + if ((self = [super init])) { UIWindow *parentView = [BlockBackground sharedInstance]; CGRect frame = parentView.bounds; @@ -46,30 +45,22 @@ - (id)initWithTitle:(NSString *)title _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; _blocks = [[NSMutableArray alloc] init]; - _completionBlocks = [[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; @@ -78,59 +69,29 @@ - (id)initWithTitle:(NSString *)title labelView.text = title; labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - _view = [[UIView alloc] initWithFrame:frame]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - _blocks = [[NSMutableArray alloc] init]; - _height = kActionSheetTopMargin; - _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)]; - 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; - labelView.shadowColor = kActionSheetTitleShadowColor; - labelView.shadowOffset = kActionSheetTitleShadowOffset; - labelView.text = title; - - labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + 5; + + [_view addSubview:labelView]; + [labelView release]; + + _height += size.height + 5; + } + _vignetteBackground = NO; } - _vignetteBackground = NO; - } - - return self; + + return self; } -- (void) dealloc +- (void) dealloc { [_view release]; [_blocks release]; [_completionBlocks release]; - [_tintColor release]; + [_tintColor release]; [super dealloc]; } - (NSUInteger)buttonCount { - return _blocks.count; + return _blocks.count; } #pragma mark - Add buttons @@ -177,27 +138,27 @@ - (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void } - (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; + [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; } - (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"black" block:block atIndex:-1]; + [self addButtonWithTitle:title color:@"black" block:block atIndex:-1]; } - (void)addButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"gray" block:block atIndex:-1]; + [self addButtonWithTitle:title color:@"gray" block:block atIndex:-1]; } - (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block { - [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; + [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; } - (void)setCancelButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block { - [self addButtonWithTitle:title color:@"black" block:block atIndex:index]; + [self addButtonWithTitle:title color:@"black" block:block atIndex:index]; } - (void)addButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block { - [self addButtonWithTitle:title color:@"gray" block:block atIndex:index]; + [self addButtonWithTitle:title color:@"gray" block:block atIndex:index]; } #pragma mark - Add button with block and animation completion block @@ -321,7 +282,7 @@ - (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]) @@ -372,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; diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m.orig b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m.orig deleted file mode 100755 index 3691020..0000000 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet.m.orig +++ /dev/null @@ -1,517 +0,0 @@ -// -// BlockActionSheet.m -// -// - -#import "BlockActionSheet.h" -#import "BlockBackground.h" -#import "BlockUI.h" - -@implementation BlockActionSheet - -@synthesize view = _view; -@synthesize vignetteBackground = _vignetteBackground; - -static UIImage *background = nil; -static UIFont *titleFont = nil; -static UIFont *buttonFont = nil; - -#pragma mark - init - -+ (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 tintColor:nil textColor:nil] autorelease]; -} - -<<<<<<< HEAD -- (id)initWithTitle:(NSString *)title -{ - if ((self = [super init])) - { - UIWindow *parentView = [BlockBackground sharedInstance]; - CGRect frame = parentView.bounds; - - _view = [[UIView alloc] initWithFrame:frame]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - _blocks = [[NSMutableArray alloc] init]; - _completionBlocks = [[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)); - } - - UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kActionSheetBorder, _height, frame.size.width-kActionSheetBorder*2, size.height)]; - labelView.font = titleFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kActionSheetTitleTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kActionSheetTitleShadowColor; - labelView.shadowOffset = kActionSheetTitleShadowOffset; - labelView.text = title; - - labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + 5; - } - _vignetteBackground = NO; -======= -+ (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; - - _view = [[UIView alloc] initWithFrame:frame]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - _blocks = [[NSMutableArray alloc] init]; - _height = kActionSheetTopMargin; - _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)]; - 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; - labelView.shadowColor = kActionSheetTitleShadowColor; - labelView.shadowOffset = kActionSheetTitleShadowOffset; - labelView.text = title; - - labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + 5; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - _vignetteBackground = NO; - } - - return self; -} - -<<<<<<< HEAD -- (void) dealloc -{ - [_view release]; - [_blocks release]; - [_completionBlocks release]; - [super dealloc]; -======= -- (void)dealloc { - [_view release]; - [_blocks release]; - [_tintColor release]; - [super dealloc]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -- (NSUInteger)buttonCount { - return _blocks.count; -} - -<<<<<<< HEAD -#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) - { - [_blocks insertObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil] - atIndex:index]; - [_blocks insertObject:[NSArray arrayWithObjects: - completionBlock ? [[completionBlock copy] autorelease] : [NSNull null], - title, - color, - nil] - atIndex:index]; - } - else - { - [_blocks addObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil]]; - [_completionBlocks addObject:[NSArray arrayWithObjects: - completionBlock ? [[completionBlock copy] autorelease] : [NSNull null], - title, - color, - nil]]; - } -} - -#pragma mark - Add buttons with block - -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; -======= -- (void)addButtonWithTitle:(NSString *)title color:(NSString *)color block:(void (^)())block atIndex:(NSInteger)index { - if (index >= 0) { - [_blocks - insertObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil] - atIndex:index]; - } else { - [_blocks - addObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil]]; - } -} - -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"black" block:block atIndex:-1]; -} - -- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"gray" block:block atIndex:-1]; -} - -<<<<<<< HEAD -#pragma mark - Add buttons at index with block - -- (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; -======= -- (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block { - [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -- (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 { - [self addButtonWithTitle:title color:@"gray" block:block atIndex:index]; -} - -<<<<<<< HEAD -#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; - for (NSArray *block in _blocks) - { - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width)>>1 topCapHeight:0]; - - UIImage *highlightedImage = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button-highlighted.png", color]]; - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width-kActionSheetBorder*2, kActionSheetButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; -#pragma clang diagnostic pop - } - else { - button.titleLabel.minimumScaleFactor = 0.1; - } - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kActionSheetButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i++; - - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) - { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - } - [button setTitleColor:kActionSheetButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kActionSheetButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - button.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:button]; - _height += kActionSheetButtonHeight + kActionSheetBorder; -======= -- (void)showInView:(UIView *)view { - NSUInteger i = 1; - for (NSArray *block in _blocks) { - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width) >> 1 topCapHeight:0]; - - UIImage *highlightedImage = - [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button-highlighted.png", color]]; - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width - kActionSheetBorder * 2, - kActionSheetButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { -#pragma clan diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; -#pragma clan diagnostic pop - } else { - button.titleLabel.minimumScaleFactor = 0.1; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kActionSheetButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i++; - -<<<<<<< HEAD -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated -{ - // Block Execution - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) - { - id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) - { - ((void (^)())obj)(); - } -======= - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - [button setTitleColor:kActionSheetButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kActionSheetButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - button.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:button]; - _height += kActionSheetButtonHeight + kActionSheetBorder; - } - - UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; - modalBackground.image = background; - if (_tintColor) { - modalBackground.image = [modalBackground.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; - modalBackground.tintColor = _tintColor; - } - modalBackground.contentMode = UIViewContentModeScaleToFill; - modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [_view insertSubview:modalBackground atIndex:0]; - [modalBackground release]; - - [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; - [[BlockBackground sharedInstance] addToMainWindow:_view]; - CGRect frame = _view.frame; - frame.origin.y = [BlockBackground sharedInstance].bounds.size.height; - frame.size.height = _height + kActionSheetBounce; - _view.frame = frame; - - __block CGPoint center = _view.center; - center.y -= _height + kActionSheetBounce; - - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [BlockBackground sharedInstance].alpha = 1.0f; - _view.center = center; - } - completion:^(BOOL finished) { - [UIView animateWithDuration:0.1 - delay:0.0 - options:UIViewAnimationOptionAllowUserInteraction - animations:^{ -<<<<<<< HEAD - _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 - { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; -======= - center.y += kActionSheetBounce; - _view.center = center; - } - completion:nil]; - }]; - - [self retain]; -} - -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) { - id obj = [[_blocks objectAtIndex:buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) { - ((void (^)())obj)(); ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - } - - if (animated) { - CGPoint center = _view.center; - center.y += _view.bounds.size.height; - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseIn - animations:^{ - _view.center = center; - [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; - } - completion:^(BOOL finished) { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; - _view = nil; - [self autorelease]; - }]; - } else { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; - _view = nil; - [self autorelease]; - } -} - -#pragma mark - Action - -<<<<<<< HEAD -- (void)buttonClicked:(id)sender -{ - /* Run the button's block */ - NSInteger buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; -======= -- (void)buttonClicked:(id)sender { - /* Run the button's block */ - int buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -@end diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_BACKUP_1091.m b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_BACKUP_1091.m deleted file mode 100755 index 3691020..0000000 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_BACKUP_1091.m +++ /dev/null @@ -1,517 +0,0 @@ -// -// BlockActionSheet.m -// -// - -#import "BlockActionSheet.h" -#import "BlockBackground.h" -#import "BlockUI.h" - -@implementation BlockActionSheet - -@synthesize view = _view; -@synthesize vignetteBackground = _vignetteBackground; - -static UIImage *background = nil; -static UIFont *titleFont = nil; -static UIFont *buttonFont = nil; - -#pragma mark - init - -+ (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 tintColor:nil textColor:nil] autorelease]; -} - -<<<<<<< HEAD -- (id)initWithTitle:(NSString *)title -{ - if ((self = [super init])) - { - UIWindow *parentView = [BlockBackground sharedInstance]; - CGRect frame = parentView.bounds; - - _view = [[UIView alloc] initWithFrame:frame]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - _blocks = [[NSMutableArray alloc] init]; - _completionBlocks = [[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)); - } - - UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kActionSheetBorder, _height, frame.size.width-kActionSheetBorder*2, size.height)]; - labelView.font = titleFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kActionSheetTitleTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kActionSheetTitleShadowColor; - labelView.shadowOffset = kActionSheetTitleShadowOffset; - labelView.text = title; - - labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + 5; - } - _vignetteBackground = NO; -======= -+ (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; - - _view = [[UIView alloc] initWithFrame:frame]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - _blocks = [[NSMutableArray alloc] init]; - _height = kActionSheetTopMargin; - _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)]; - 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; - labelView.shadowColor = kActionSheetTitleShadowColor; - labelView.shadowOffset = kActionSheetTitleShadowOffset; - labelView.text = title; - - labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + 5; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - _vignetteBackground = NO; - } - - return self; -} - -<<<<<<< HEAD -- (void) dealloc -{ - [_view release]; - [_blocks release]; - [_completionBlocks release]; - [super dealloc]; -======= -- (void)dealloc { - [_view release]; - [_blocks release]; - [_tintColor release]; - [super dealloc]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -- (NSUInteger)buttonCount { - return _blocks.count; -} - -<<<<<<< HEAD -#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) - { - [_blocks insertObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil] - atIndex:index]; - [_blocks insertObject:[NSArray arrayWithObjects: - completionBlock ? [[completionBlock copy] autorelease] : [NSNull null], - title, - color, - nil] - atIndex:index]; - } - else - { - [_blocks addObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil]]; - [_completionBlocks addObject:[NSArray arrayWithObjects: - completionBlock ? [[completionBlock copy] autorelease] : [NSNull null], - title, - color, - nil]]; - } -} - -#pragma mark - Add buttons with block - -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; -======= -- (void)addButtonWithTitle:(NSString *)title color:(NSString *)color block:(void (^)())block atIndex:(NSInteger)index { - if (index >= 0) { - [_blocks - insertObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil] - atIndex:index]; - } else { - [_blocks - addObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil]]; - } -} - -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"black" block:block atIndex:-1]; -} - -- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"gray" block:block atIndex:-1]; -} - -<<<<<<< HEAD -#pragma mark - Add buttons at index with block - -- (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; -======= -- (void)setDestructiveButtonWithTitle:(NSString *)title atIndex:(NSInteger)index block:(void (^)())block { - [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -- (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 { - [self addButtonWithTitle:title color:@"gray" block:block atIndex:index]; -} - -<<<<<<< HEAD -#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; - for (NSArray *block in _blocks) - { - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width)>>1 topCapHeight:0]; - - UIImage *highlightedImage = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button-highlighted.png", color]]; - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width-kActionSheetBorder*2, kActionSheetButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; -#pragma clang diagnostic pop - } - else { - button.titleLabel.minimumScaleFactor = 0.1; - } - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kActionSheetButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i++; - - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) - { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - } - [button setTitleColor:kActionSheetButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kActionSheetButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - button.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:button]; - _height += kActionSheetButtonHeight + kActionSheetBorder; -======= -- (void)showInView:(UIView *)view { - NSUInteger i = 1; - for (NSArray *block in _blocks) { - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width) >> 1 topCapHeight:0]; - - UIImage *highlightedImage = - [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button-highlighted.png", color]]; - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width - kActionSheetBorder * 2, - kActionSheetButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { -#pragma clan diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; -#pragma clan diagnostic pop - } else { - button.titleLabel.minimumScaleFactor = 0.1; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kActionSheetButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i++; - -<<<<<<< HEAD -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated -{ - // Block Execution - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) - { - id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) - { - ((void (^)())obj)(); - } -======= - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - [button setTitleColor:kActionSheetButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kActionSheetButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - button.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:button]; - _height += kActionSheetButtonHeight + kActionSheetBorder; - } - - UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; - modalBackground.image = background; - if (_tintColor) { - modalBackground.image = [modalBackground.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; - modalBackground.tintColor = _tintColor; - } - modalBackground.contentMode = UIViewContentModeScaleToFill; - modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [_view insertSubview:modalBackground atIndex:0]; - [modalBackground release]; - - [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; - [[BlockBackground sharedInstance] addToMainWindow:_view]; - CGRect frame = _view.frame; - frame.origin.y = [BlockBackground sharedInstance].bounds.size.height; - frame.size.height = _height + kActionSheetBounce; - _view.frame = frame; - - __block CGPoint center = _view.center; - center.y -= _height + kActionSheetBounce; - - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [BlockBackground sharedInstance].alpha = 1.0f; - _view.center = center; - } - completion:^(BOOL finished) { - [UIView animateWithDuration:0.1 - delay:0.0 - options:UIViewAnimationOptionAllowUserInteraction - animations:^{ -<<<<<<< HEAD - _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 - { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; -======= - center.y += kActionSheetBounce; - _view.center = center; - } - completion:nil]; - }]; - - [self retain]; -} - -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) { - id obj = [[_blocks objectAtIndex:buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) { - ((void (^)())obj)(); ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - } - - if (animated) { - CGPoint center = _view.center; - center.y += _view.bounds.size.height; - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseIn - animations:^{ - _view.center = center; - [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; - } - completion:^(BOOL finished) { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; - _view = nil; - [self autorelease]; - }]; - } else { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; - _view = nil; - [self autorelease]; - } -} - -#pragma mark - Action - -<<<<<<< HEAD -- (void)buttonClicked:(id)sender -{ - /* Run the button's block */ - NSInteger buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; -======= -- (void)buttonClicked:(id)sender { - /* Run the button's block */ - int buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -@end diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_BASE_1091.m b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_BASE_1091.m deleted file mode 100644 index 222d48c..0000000 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_BASE_1091.m +++ /dev/null @@ -1,273 +0,0 @@ -// -// BlockActionSheet.m -// -// - -#import "BlockActionSheet.h" -#import "BlockBackground.h" -#import "BlockUI.h" - -@implementation BlockActionSheet - -@synthesize view = _view; -@synthesize vignetteBackground = _vignetteBackground; - -static UIImage *background = nil; -static UIFont *titleFont = nil; -static UIFont *buttonFont = nil; - -#pragma mark - init - -+ (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)initWithTitle:(NSString *)title -{ - if ((self = [super init])) - { - UIWindow *parentView = [BlockBackground sharedInstance]; - CGRect frame = parentView.bounds; - - _view = [[UIView alloc] initWithFrame:frame]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - _blocks = [[NSMutableArray alloc] init]; - _height = kActionSheetTopMargin; - - 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)]; - labelView.font = titleFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kActionSheetTitleTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kActionSheetTitleShadowColor; - labelView.shadowOffset = kActionSheetTitleShadowOffset; - labelView.text = title; - - labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + 5; - } - _vignetteBackground = NO; - } - - return self; -} - -- (void) dealloc -{ - [_view release]; - [_blocks release]; - [super dealloc]; -} - -- (NSUInteger)buttonCount -{ - return _blocks.count; -} - -- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block atIndex:(NSInteger)index -{ - if (index >= 0) - { - [_blocks insertObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil] - atIndex:index]; - } - else - { - [_blocks addObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil]]; - } -} - -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; -} - -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"black" block:block atIndex:-1]; -} - -- (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 -{ - [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; -} - -- (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 -{ - [self addButtonWithTitle:title color:@"gray" block:block atIndex:index]; -} - -- (void)showInView:(UIView *)view -{ - NSUInteger i = 1; - for (NSArray *block in _blocks) - { - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width)>>1 topCapHeight:0]; - - UIImage *highlightedImage = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button-highlighted.png", color]]; - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width-kActionSheetBorder*2, kActionSheetButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { -#pragma clan diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; -#pragma clan diagnostic pop - } - else { - button.titleLabel.minimumScaleFactor = 0.1; - } - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kActionSheetButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i++; - - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) - { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - } - [button setTitleColor:kActionSheetButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kActionSheetButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - button.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:button]; - _height += kActionSheetButtonHeight + kActionSheetBorder; - } - - UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; - modalBackground.image = background; - modalBackground.contentMode = UIViewContentModeScaleToFill; - modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [_view insertSubview:modalBackground atIndex:0]; - [modalBackground release]; - - [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; - [[BlockBackground sharedInstance] addToMainWindow:_view]; - CGRect frame = _view.frame; - frame.origin.y = [BlockBackground sharedInstance].bounds.size.height; - frame.size.height = _height + kActionSheetBounce; - _view.frame = frame; - - __block CGPoint center = _view.center; - center.y -= _height + kActionSheetBounce; - - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [BlockBackground sharedInstance].alpha = 1.0f; - _view.center = center; - } completion:^(BOOL finished) { - [UIView animateWithDuration:0.1 - delay:0.0 - options:UIViewAnimationOptionAllowUserInteraction - animations:^{ - center.y += kActionSheetBounce; - _view.center = center; - } completion:nil]; - }]; - - [self retain]; -} - -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated -{ - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) - { - id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) - { - ((void (^)())obj)(); - } - } - - if (animated) - { - CGPoint center = _view.center; - center.y += _view.bounds.size.height; - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseIn - animations:^{ - _view.center = center; - [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; - } completion:^(BOOL finished) { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; - }]; - } - else - { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; - } -} - -#pragma mark - Action - -- (void)buttonClicked:(id)sender -{ - /* Run the button's block */ - int buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; -} - -@end diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_LOCAL_1091.m b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_LOCAL_1091.m deleted file mode 100644 index c16d9f8..0000000 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_LOCAL_1091.m +++ /dev/null @@ -1,362 +0,0 @@ -// -// BlockActionSheet.m -// -// - -#import "BlockActionSheet.h" -#import "BlockBackground.h" -#import "BlockUI.h" - -@implementation BlockActionSheet - -@synthesize view = _view; -@synthesize vignetteBackground = _vignetteBackground; - -static UIImage *background = nil; -static UIFont *titleFont = nil; -static UIFont *buttonFont = nil; - -#pragma mark - init - -+ (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)initWithTitle:(NSString *)title -{ - if ((self = [super init])) - { - UIWindow *parentView = [BlockBackground sharedInstance]; - CGRect frame = parentView.bounds; - - _view = [[UIView alloc] initWithFrame:frame]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - _blocks = [[NSMutableArray alloc] init]; - _completionBlocks = [[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)); - } - - UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kActionSheetBorder, _height, frame.size.width-kActionSheetBorder*2, size.height)]; - labelView.font = titleFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kActionSheetTitleTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kActionSheetTitleShadowColor; - labelView.shadowOffset = kActionSheetTitleShadowOffset; - labelView.text = title; - - labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + 5; - } - _vignetteBackground = NO; - } - - return self; -} - -- (void) dealloc -{ - [_view release]; - [_blocks release]; - [_completionBlocks release]; - [super dealloc]; -} - -- (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) - { - [_blocks insertObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil] - atIndex:index]; - [_blocks insertObject:[NSArray arrayWithObjects: - completionBlock ? [[completionBlock copy] autorelease] : [NSNull null], - title, - color, - nil] - atIndex:index]; - } - else - { - [_blocks addObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil]]; - [_completionBlocks addObject:[NSArray arrayWithObjects: - completionBlock ? [[completionBlock copy] autorelease] : [NSNull null], - title, - color, - nil]]; - } -} - -#pragma mark - Add buttons with block - -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; -} - -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"black" block:block atIndex:-1]; -} - -- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block -{ - [self addButtonWithTitle:title color:@"gray" block:block atIndex:-1]; -} - -#pragma mark - Add buttons at index with 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 -{ - [self addButtonWithTitle:title color:@"black" block:block atIndex:index]; -} - -- (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; - for (NSArray *block in _blocks) - { - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width)>>1 topCapHeight:0]; - - UIImage *highlightedImage = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button-highlighted.png", color]]; - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width-kActionSheetBorder*2, kActionSheetButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; -#pragma clang diagnostic pop - } - else { - button.titleLabel.minimumScaleFactor = 0.1; - } - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kActionSheetButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i++; - - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) - { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - } - [button setTitleColor:kActionSheetButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kActionSheetButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - button.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:button]; - _height += kActionSheetButtonHeight + kActionSheetBorder; - } - - UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; - modalBackground.image = background; - modalBackground.contentMode = UIViewContentModeScaleToFill; - modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [_view insertSubview:modalBackground atIndex:0]; - [modalBackground release]; - - [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; - [[BlockBackground sharedInstance] addToMainWindow:_view]; - CGRect frame = _view.frame; - frame.origin.y = [BlockBackground sharedInstance].bounds.size.height; - frame.size.height = _height + kActionSheetBounce; - _view.frame = frame; - - __block CGPoint center = _view.center; - center.y -= _height + kActionSheetBounce; - - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [BlockBackground sharedInstance].alpha = 1.0f; - _view.center = center; - } completion:^(BOOL finished) { - [UIView animateWithDuration:0.1 - delay:0.0 - options:UIViewAnimationOptionAllowUserInteraction - animations:^{ - center.y += kActionSheetBounce; - _view.center = center; - } completion:nil]; - }]; - - [self retain]; -} - -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated -{ - // Block Execution - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) - { - id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) - { - ((void (^)())obj)(); - } - } - - if (animated) - { - CGPoint center = _view.center; - center.y += _view.bounds.size.height; - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseIn - animations:^{ - _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 - { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; - } -} - -#pragma mark - Action - -- (void)buttonClicked:(id)sender -{ - /* Run the button's block */ - NSInteger buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; -} - -@end diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_REMOTE_1091.m b/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_REMOTE_1091.m deleted file mode 100644 index 543b83b..0000000 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockActionSheet_REMOTE_1091.m +++ /dev/null @@ -1,259 +0,0 @@ -// -// BlockActionSheet.m -// -// - -#import "BlockActionSheet.h" -#import "BlockBackground.h" -#import "BlockUI.h" - -@implementation BlockActionSheet - -@synthesize view = _view; -@synthesize vignetteBackground = _vignetteBackground; - -static UIImage *background = nil; -static UIFont *titleFont = nil; -static UIFont *buttonFont = nil; - -#pragma mark - init - -+ (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 tintColor:nil textColor:nil] autorelease]; -} - -+ (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; - - _view = [[UIView alloc] initWithFrame:frame]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; - - _blocks = [[NSMutableArray alloc] init]; - _height = kActionSheetTopMargin; - _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)]; - 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; - labelView.shadowColor = kActionSheetTitleShadowColor; - labelView.shadowOffset = kActionSheetTitleShadowOffset; - labelView.text = title; - - labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + 5; - } - _vignetteBackground = NO; - } - - return self; -} - -- (void)dealloc { - [_view release]; - [_blocks release]; - [_tintColor release]; - [super dealloc]; -} - -- (NSUInteger)buttonCount { - return _blocks.count; -} - -- (void)addButtonWithTitle:(NSString *)title color:(NSString *)color block:(void (^)())block atIndex:(NSInteger)index { - if (index >= 0) { - [_blocks - insertObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil] - atIndex:index]; - } else { - [_blocks - addObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil]]; - } -} - -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"red" block:block atIndex:-1]; -} - -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"black" block:block atIndex:-1]; -} - -- (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 { - [self addButtonWithTitle:title color:@"red" block:block atIndex:index]; -} - -- (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 { - [self addButtonWithTitle:title color:@"gray" block:block atIndex:index]; -} - -- (void)showInView:(UIView *)view { - NSUInteger i = 1; - for (NSArray *block in _blocks) { - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width) >> 1 topCapHeight:0]; - - UIImage *highlightedImage = - [UIImage imageNamed:[NSString stringWithFormat:@"action-%@-button-highlighted.png", color]]; - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(kActionSheetBorder, _height, _view.bounds.size.width - kActionSheetBorder * 2, - kActionSheetButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { -#pragma clan diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; -#pragma clan diagnostic pop - } else { - button.titleLabel.minimumScaleFactor = 0.1; - } - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kActionSheetButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i++; - - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - } - [button setTitleColor:kActionSheetButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kActionSheetButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - button.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - [_view addSubview:button]; - _height += kActionSheetButtonHeight + kActionSheetBorder; - } - - UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; - modalBackground.image = background; - if (_tintColor) { - modalBackground.image = [modalBackground.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; - modalBackground.tintColor = _tintColor; - } - modalBackground.contentMode = UIViewContentModeScaleToFill; - modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [_view insertSubview:modalBackground atIndex:0]; - [modalBackground release]; - - [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; - [[BlockBackground sharedInstance] addToMainWindow:_view]; - CGRect frame = _view.frame; - frame.origin.y = [BlockBackground sharedInstance].bounds.size.height; - frame.size.height = _height + kActionSheetBounce; - _view.frame = frame; - - __block CGPoint center = _view.center; - center.y -= _height + kActionSheetBounce; - - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [BlockBackground sharedInstance].alpha = 1.0f; - _view.center = center; - } - completion:^(BOOL finished) { - [UIView animateWithDuration:0.1 - delay:0.0 - options:UIViewAnimationOptionAllowUserInteraction - animations:^{ - center.y += kActionSheetBounce; - _view.center = center; - } - completion:nil]; - }]; - - [self retain]; -} - -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) { - id obj = [[_blocks objectAtIndex:buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) { - ((void (^)())obj)(); - } - } - - if (animated) { - CGPoint center = _view.center; - center.y += _view.bounds.size.height; - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseIn - animations:^{ - _view.center = center; - [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; - } - completion:^(BOOL finished) { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; - _view = nil; - [self autorelease]; - }]; - } else { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; - _view = nil; - [self autorelease]; - } -} - -#pragma mark - Action - -- (void)buttonClicked:(id)sender { - /* Run the button's block */ - int buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; -} - -@end diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h index 9d60e79..ad54789 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h @@ -7,7 +7,7 @@ @interface BlockAlertView : NSObject { @protected - UIView *_view; + UIScrollView *_view; NSMutableArray *_blocks; NSMutableArray *_completionBlocks; CGFloat _height; diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h.orig b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h.orig deleted file mode 100755 index dc48cfe..0000000 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.h.orig +++ /dev/null @@ -1,78 +0,0 @@ -// -// BlockAlertView.h -// -// - -#import - -@interface BlockAlertView : NSObject { -<<<<<<< HEAD -@protected - UIView *_view; - NSMutableArray *_blocks; - NSMutableArray *_completionBlocks; - CGFloat _height; - NSString *_title; - NSString *_message; - BOOL _shown; - BOOL _cancelBounce; -======= - @protected - UIScrollView *_view; - NSMutableArray *_blocks; - CGFloat _height; - NSString *_title; - NSString *_message; - BOOL _shown; - BOOL _cancelBounce; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -+ (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message; -+ (BlockAlertView *)alertWithTitle:(NSString *)title - message:(NSString *)message - tintColor:(UIColor *)tintColor - textColor:(UIColor *)textColor; - -+ (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message; -+ (void)showErrorAlert:(NSError *)error; - -- (id)initWithTitle:(NSString *)title message:(NSString *)message; - -<<<<<<< HEAD -// Add button with block -======= -- (id)initWithTitle:(NSString *)title - message:(NSString *)message - tintColor:(UIColor *)tintColor - textColor:(UIColor *)textColor; - ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block; -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block; -- (void)addButtonWithTitle:(NSString *)title 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; - -// Images should be named in the form "alert-IDENTIFIER-button.png" -- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString *)identifier block:(void (^)())block; - -- (void)addComponents:(CGRect)frame; - -- (void)show; -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated; - -- (void)setupDisplay; - -@property(nonatomic, retain) UIImage *backgroundImage; -@property(nonatomic, readonly) UIScrollView *view; -@property(nonatomic, readwrite) BOOL vignetteBackground; -@property(nonatomic, retain) UIColor *tintColor; -@property(nonatomic, retain) UIColor *textColor; -@property(nonatomic, retain) UIFont *messageFont; -@property(nonatomic) BOOL allButtonInLine; - -@end diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m index c722403..d4d9103 100755 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m +++ b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m @@ -26,181 +26,181 @@ @implementation BlockAlertView #pragma mark - init + (void)initialize { - if (self == [BlockAlertView class]) { - background = [UIImage imageNamed:kAlertViewBackground]; - background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; - - backgroundlandscape = [UIImage imageNamed:kAlertViewBackgroundLandscape]; - backgroundlandscape = + if (self == [BlockAlertView class]) { + background = [UIImage imageNamed:kAlertViewBackground]; + background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; + + backgroundlandscape = [UIImage imageNamed:kAlertViewBackgroundLandscape]; + backgroundlandscape = [[backgroundlandscape stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; - - titleFont = [kAlertViewTitleFont retain]; - messageFont = [kAlertViewMessageFont retain]; - buttonFont = [kAlertViewButtonFont retain]; - } + + titleFont = [kAlertViewTitleFont retain]; + messageFont = [kAlertViewMessageFont retain]; + buttonFont = [kAlertViewButtonFont retain]; + } } + (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message { - return [[[BlockAlertView alloc] initWithTitle:title message:message tintColor:nil textColor:nil] autorelease]; + return [[[BlockAlertView alloc] initWithTitle:title message:message tintColor:nil textColor:nil] autorelease]; } + (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message tintColor:(UIColor *)tintColor textColor:(UIColor *)textColor { - return [ - [[BlockAlertView alloc] initWithTitle:title message:message tintColor:tintColor textColor:textColor] autorelease]; + return [ + [[BlockAlertView alloc] initWithTitle:title message:message tintColor:tintColor textColor:textColor] autorelease]; } + (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message { - BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:title message:message tintColor:nil textColor:nil]; - [alert setCancelButtonWithTitle:NSLocalizedString(@"Dismiss", nil) block:nil]; - [alert show]; - [alert release]; + BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:title message:message tintColor:nil textColor:nil]; + [alert setCancelButtonWithTitle:NSLocalizedString(@"Dismiss", nil) block:nil]; + [alert show]; + [alert release]; } + (void)showErrorAlert:(NSError *)error { - BlockAlertView *alert = [[BlockAlertView alloc] - initWithTitle:NSLocalizedString(@"Operation Failed", nil) - message:[NSString - stringWithFormat:NSLocalizedString(@"The operation did not complete successfully: %@", nil), - error] - tintColor:nil - textColor:nil]; - [alert setCancelButtonWithTitle:@"Dismiss" block:nil]; - [alert show]; - [alert release]; + BlockAlertView *alert = [[BlockAlertView alloc] + initWithTitle:NSLocalizedString(@"Operation Failed", nil) + message:[NSString + stringWithFormat:NSLocalizedString(@"The operation did not complete successfully: %@", nil), + error] + tintColor:nil + textColor:nil]; + [alert setCancelButtonWithTitle:@"Dismiss" block:nil]; + [alert show]; + [alert release]; } /////////////////////////////////////////////////////////////////////////////////////////////////// #pragma mark - NSObject - (void)addComponents:(CGRect)frame { - if (_title) { - CGSize size = [_title sizeWithFont:titleFont - constrainedToSize:CGSizeMake(frame.size.width - kAlertViewBorder * 2, 1000) - lineBreakMode:NSLineBreakByWordWrapping]; - - UILabel *labelView = [[UILabel alloc] - initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width - kAlertViewBorder * 2, size.height)]; - labelView.font = titleFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = _textColor ? _textColor : kAlertViewTitleTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kAlertViewTitleShadowColor; - labelView.shadowOffset = kAlertViewTitleShadowOffset; - labelView.text = _title; - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + kAlertViewBorder; - } - - if (_message) { - CGSize size = [_message sizeWithFont:self.messageFont - constrainedToSize:CGSizeMake(frame.size.width - kAlertViewBorder * 2, 1000) - lineBreakMode:NSLineBreakByWordWrapping]; - - UILabel *labelView = [[UILabel alloc] - initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width - kAlertViewBorder * 2, size.height)]; - labelView.font = self.messageFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = _textColor ? _textColor : kAlertViewMessageTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kAlertViewMessageShadowColor; - labelView.shadowOffset = kAlertViewMessageShadowOffset; - labelView.text = _message; - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + kAlertViewBorder; - } + if (_title) { + CGSize size = [_title sizeWithFont:titleFont + constrainedToSize:CGSizeMake(frame.size.width - kAlertViewBorder * 2, 1000) + lineBreakMode:NSLineBreakByWordWrapping]; + + UILabel *labelView = [[UILabel alloc] + initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width - kAlertViewBorder * 2, size.height)]; + labelView.font = titleFont; + labelView.numberOfLines = 0; + labelView.lineBreakMode = NSLineBreakByWordWrapping; + labelView.textColor = _textColor ? _textColor : kAlertViewTitleTextColor; + labelView.backgroundColor = [UIColor clearColor]; + labelView.textAlignment = NSTextAlignmentCenter; + labelView.shadowColor = kAlertViewTitleShadowColor; + labelView.shadowOffset = kAlertViewTitleShadowOffset; + labelView.text = _title; + [_view addSubview:labelView]; + [labelView release]; + + _height += size.height + kAlertViewBorder; + } + + if (_message) { + CGSize size = [_message sizeWithFont:self.messageFont + constrainedToSize:CGSizeMake(frame.size.width - kAlertViewBorder * 2, 1000) + lineBreakMode:NSLineBreakByWordWrapping]; + + UILabel *labelView = [[UILabel alloc] + initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width - kAlertViewBorder * 2, size.height)]; + labelView.font = self.messageFont; + labelView.numberOfLines = 0; + labelView.lineBreakMode = NSLineBreakByWordWrapping; + labelView.textColor = _textColor ? _textColor : kAlertViewMessageTextColor; + labelView.backgroundColor = [UIColor clearColor]; + labelView.textAlignment = NSTextAlignmentCenter; + labelView.shadowColor = kAlertViewMessageShadowColor; + labelView.shadowOffset = kAlertViewMessageShadowOffset; + labelView.text = _message; + [_view addSubview:labelView]; + [labelView release]; + + _height += size.height + kAlertViewBorder; + } } - (void)setupDisplay { - [[_view subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - [obj removeFromSuperview]; - }]; - - UIWindow *parentView = [BlockBackground sharedInstance]; - CGRect frame = parentView.bounds; - frame.origin.x = floorf((frame.size.width - background.size.width) * 0.5); - frame.size.width = background.size.width; - - UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; - if (UIInterfaceOrientationIsLandscape(orientation)) { - frame.size.width += 150; - frame.origin.x -= 75; - } - - _view.frame = frame; - - _height = kAlertViewBorder + 15; - - if (NeedsLandscapePhoneTweaks) { - _height -= 15; // landscape phones need to trimmed a bit - } - - [self addComponents:frame]; - - if (_shown) [self show]; + [[_view subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [obj removeFromSuperview]; + }]; + + UIWindow *parentView = [BlockBackground sharedInstance]; + CGRect frame = parentView.bounds; + frame.origin.x = floorf((frame.size.width - background.size.width) * 0.5); + frame.size.width = background.size.width; + + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + if (UIInterfaceOrientationIsLandscape(orientation)) { + frame.size.width += 150; + frame.origin.x -= 75; + } + + _view.frame = frame; + + _height = kAlertViewBorder + 15; + + if (NeedsLandscapePhoneTweaks) { + _height -= 15; // landscape phones need to trimmed a bit + } + + [self addComponents:frame]; + + if (_shown) [self show]; } - (id)initWithTitle:(NSString *)title message:(NSString *)message { - return [self initWithTitle:title message:message tintColor:nil textColor:nil]; + return [self initWithTitle:title message:message tintColor:nil textColor:nil]; } - (id)initWithTitle:(NSString *)title message:(NSString *)message tintColor:(UIColor *)tintColor textColor:(UIColor *)textColor { - self = [super init]; - - if (self) { - _title = [title copy]; - _message = [message copy]; - - _view = [[UIScrollView alloc] init]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | - UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; - - _blocks = [[NSMutableArray alloc] init]; - - if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending) { - // don't register for notification, rotation is handled by iOS on 8+ - } else { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(setupDisplay) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; + self = [super init]; + + if (self) { + _title = [title copy]; + _message = [message copy]; + + _view = [[UIScrollView alloc] init]; + + _view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | + UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; + + _blocks = [[NSMutableArray alloc] init]; + + if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending) { + // don't register for notification, rotation is handled by iOS on 8+ + } else { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(setupDisplay) + name:UIApplicationDidChangeStatusBarOrientationNotification + object:nil]; + } + + self.messageFont = messageFont; + if ([self class] == [BlockAlertView class]) [self setupDisplay]; + _tintColor = [tintColor retain]; + _textColor = [textColor retain]; + _vignetteBackground = NO; } - - self.messageFont = messageFont; - if ([self class] == [BlockAlertView class]) [self setupDisplay]; - _tintColor = [tintColor retain]; - _textColor = [textColor retain]; - _vignetteBackground = NO; - } - - return self; + + return self; } - (void)dealloc { - [_title release]; - [_message release]; - [_backgroundImage release]; - [_view release]; - [_blocks release]; - [_messageFont release]; - [_tintColor release]; - [_textColor release]; - [_completionBlocks release]; - [super dealloc]; + [_title release]; + [_message release]; + [_backgroundImage release]; + [_view release]; + [_blocks release]; + [_messageFont release]; + [_tintColor release]; + [_textColor release]; + [_completionBlocks release]; + [super dealloc]; } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -225,12 +225,12 @@ - (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void nil]]; } -- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block +- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block { [self addButtonWithTitle:title color:@"gray" block:block]; } -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block +- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block { [self addButtonWithTitle:title color:@"black" block:block]; } @@ -274,7 +274,7 @@ - (void)show NSArray *block = [_blocks objectAtIndex:i]; NSString *title = [block objectAtIndex:1]; NSString *color = [block objectAtIndex:2]; - + UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button.png", color]]; image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width+1)>>1 topCapHeight:0]; @@ -394,11 +394,11 @@ - (void)show [_view addSubview:button]; if (!isSecondButton) - _height += kAlertButtonHeight + kAlertViewBorder; + _height += kAlertButtonHeight + kAlertViewBorder; index++; } - + //_height += 10; // Margin for the shadow // not sure where this came from, but it's making things look strange (I don't see a shadow, either) if (_height < background.size.height) @@ -421,14 +421,14 @@ - (void)show frame.size.height = _height; _view.frame = frame; - + UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) - modalBackground.image = backgroundlandscape; + modalBackground.image = backgroundlandscape; else - modalBackground.image = background; - + modalBackground.image = background; + modalBackground.contentMode = UIViewContentModeScaleToFill; modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [_view insertSubview:modalBackground atIndex:0]; @@ -443,7 +443,7 @@ - (void)show [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; [[BlockBackground sharedInstance] addToMainWindow:_view]; - + __block CGPoint center = _view.center; center.y = floorf([BlockBackground sharedInstance].bounds.size.height * 0.5) + kAlertViewBounce; @@ -455,7 +455,7 @@ - (void)show animations:^{ [BlockBackground sharedInstance].alpha = 1.0f; _view.center = center; - } + } completion:^(BOOL finished) { if (_cancelBounce) return; @@ -465,7 +465,7 @@ - (void)show animations:^{ center.y -= kAlertViewBounce; _view.center = center; - } + } completion:^(BOOL finished) { [[NSNotificationCenter defaultCenter] postNotificationName:@"AlertViewFinishedAnimations" object:self]; }]; @@ -474,7 +474,7 @@ - (void)show [self retain]; } -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated +- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { _shown = NO; @@ -499,17 +499,17 @@ - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)anim CGPoint center = _view.center; center.y += 20; _view.center = center; - } + } completion:^(BOOL finished) { [UIView animateWithDuration:0.4 - delay:0.0 + delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ CGRect frame = _view.frame; frame.origin.y = -frame.size.height; _view.frame = frame; [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; - } + } completion:^(BOOL finished) { // Completion block diff --git a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m.orig b/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m.orig deleted file mode 100755 index 89d48ef..0000000 --- a/BlockAlertsDemo/ToAddToYourProjects/BlockAlertView.m.orig +++ /dev/null @@ -1,865 +0,0 @@ -// -// BlockAlertView.m -// -// - -#import "BlockAlertView.h" -#import "BlockBackground.h" -#import "BlockUI.h" - -@implementation BlockAlertView - -@synthesize view = _view; -@synthesize backgroundImage = _backgroundImage; -@synthesize vignetteBackground = _vignetteBackground; -@synthesize tintColor = _tintColor; -@synthesize textColor = _textColor; -@synthesize messageFont = _messageFont; -@synthesize allButtonInLine = _allButtonInLine; - -static UIImage *background = nil; -static UIImage *backgroundlandscape = nil; -static UIFont *titleFont = nil; -static UIFont *messageFont = nil; -static UIFont *buttonFont = nil; - -#pragma mark - init - -+ (void)initialize { - if (self == [BlockAlertView class]) { - background = [UIImage imageNamed:kAlertViewBackground]; - background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; - - backgroundlandscape = [UIImage imageNamed:kAlertViewBackgroundLandscape]; - backgroundlandscape = - [[backgroundlandscape stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; - - titleFont = [kAlertViewTitleFont retain]; - messageFont = [kAlertViewMessageFont retain]; - buttonFont = [kAlertViewButtonFont retain]; - } -} - -+ (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message { - return [[[BlockAlertView alloc] initWithTitle:title message:message tintColor:nil textColor:nil] autorelease]; -} - -+ (BlockAlertView *)alertWithTitle:(NSString *)title - message:(NSString *)message - tintColor:(UIColor *)tintColor - textColor:(UIColor *)textColor { - return [ - [[BlockAlertView alloc] initWithTitle:title message:message tintColor:tintColor textColor:textColor] autorelease]; -} - -+ (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message { - BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:title message:message tintColor:nil textColor:nil]; - [alert setCancelButtonWithTitle:NSLocalizedString(@"Dismiss", nil) block:nil]; - [alert show]; - [alert release]; -} - -+ (void)showErrorAlert:(NSError *)error { - BlockAlertView *alert = [[BlockAlertView alloc] - initWithTitle:NSLocalizedString(@"Operation Failed", nil) - message:[NSString - stringWithFormat:NSLocalizedString(@"The operation did not complete successfully: %@", nil), - error] - tintColor:nil - textColor:nil]; - [alert setCancelButtonWithTitle:@"Dismiss" block:nil]; - [alert show]; - [alert release]; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// -#pragma mark - NSObject - -- (void)addComponents:(CGRect)frame { -<<<<<<< HEAD - 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-kAlertViewBorder*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)); - } - - UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width-kAlertViewBorder*2, size.height)]; - labelView.font = titleFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kAlertViewTitleTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kAlertViewTitleShadowColor; - labelView.shadowOffset = kAlertViewTitleShadowOffset; - labelView.text = _title; - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + kAlertViewBorder; - } - - if (_message) - { - CGSize size; - if (IOS_LESS_THAN_7) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - size = [_message sizeWithFont:messageFont constrainedToSize:CGSizeMake(frame.size.width-kAlertViewBorder*2, 1000) lineBreakMode:NSLineBreakByWordWrapping]; -#pragma clang diagnostic pop - } - else { - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping; - size = [_message boundingRectWithSize:CGSizeMake(frame.size.width-kAlertViewBorder*2, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSParagraphStyleAttributeName : paragraphStyle, NSFontAttributeName : messageFont} context:nil].size; - size = CGSizeMake(ceilf(size.width), ceilf(size.height)); - } - - UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width-kAlertViewBorder*2, size.height)]; - labelView.font = messageFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = kAlertViewMessageTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kAlertViewMessageShadowColor; - labelView.shadowOffset = kAlertViewMessageShadowOffset; - labelView.text = _message; - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + kAlertViewBorder; - } -======= - if (_title) { - CGSize size = [_title sizeWithFont:titleFont - constrainedToSize:CGSizeMake(frame.size.width - kAlertViewBorder * 2, 1000) - lineBreakMode:NSLineBreakByWordWrapping]; - - UILabel *labelView = [[UILabel alloc] - initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width - kAlertViewBorder * 2, size.height)]; - labelView.font = titleFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = _textColor ? _textColor : kAlertViewTitleTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kAlertViewTitleShadowColor; - labelView.shadowOffset = kAlertViewTitleShadowOffset; - labelView.text = _title; - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + kAlertViewBorder; - } - - if (_message) { - CGSize size = [_message sizeWithFont:self.messageFont - constrainedToSize:CGSizeMake(frame.size.width - kAlertViewBorder * 2, 1000) - lineBreakMode:NSLineBreakByWordWrapping]; - - UILabel *labelView = [[UILabel alloc] - initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width - kAlertViewBorder * 2, size.height)]; - labelView.font = self.messageFont; - labelView.numberOfLines = 0; - labelView.lineBreakMode = NSLineBreakByWordWrapping; - labelView.textColor = _textColor ? _textColor : kAlertViewMessageTextColor; - labelView.backgroundColor = [UIColor clearColor]; - labelView.textAlignment = NSTextAlignmentCenter; - labelView.shadowColor = kAlertViewMessageShadowColor; - labelView.shadowOffset = kAlertViewMessageShadowOffset; - labelView.text = _message; - [_view addSubview:labelView]; - [labelView release]; - - _height += size.height + kAlertViewBorder; - } ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -- (void)setupDisplay { - [[_view subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - [obj removeFromSuperview]; - }]; - - UIWindow *parentView = [BlockBackground sharedInstance]; - CGRect frame = parentView.bounds; - frame.origin.x = floorf((frame.size.width - background.size.width) * 0.5); - frame.size.width = background.size.width; - - UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; - if (UIInterfaceOrientationIsLandscape(orientation)) { - frame.size.width += 150; - frame.origin.x -= 75; - } - - _view.frame = frame; - - _height = kAlertViewBorder + 15; - - if (NeedsLandscapePhoneTweaks) { - _height -= 15; // landscape phones need to trimmed a bit - } - - [self addComponents:frame]; - - if (_shown) [self show]; -} - -- (id)initWithTitle:(NSString *)title message:(NSString *)message { - return [self initWithTitle:title message:message tintColor:nil textColor:nil]; -} - -<<<<<<< HEAD -- (id)initWithTitle:(NSString *)title message:(NSString *)message -{ - self = [super init]; - - if (self) - { - _title = [title copy]; - _message = [message copy]; - - _view = [[UIView alloc] init]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; - - _blocks = [[NSMutableArray alloc] init]; - _completionBlocks = [[NSMutableArray alloc] init]; - - if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending){ - // don't register for notification, rotation is handled by iOS on 8+ - } - else { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(setupDisplay) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; - } - - if ([self class] == [BlockAlertView class]) - [self setupDisplay]; - - _vignetteBackground = NO; -======= -- (id)initWithTitle:(NSString *)title - message:(NSString *)message - tintColor:(UIColor *)tintColor - textColor:(UIColor *)textColor { - self = [super init]; - - if (self) { - _title = [title copy]; - _message = [message copy]; - - _view = [[UIScrollView alloc] init]; - - _view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | - UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; - - _blocks = [[NSMutableArray alloc] init]; - - if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] == NSOrderedDescending) { - // don't register for notification, rotation is handled by iOS on 8+ - } else { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(setupDisplay) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - - self.messageFont = messageFont; - if ([self class] == [BlockAlertView class]) [self setupDisplay]; - _tintColor = [tintColor retain]; - _textColor = [textColor retain]; - _vignetteBackground = NO; - } - - return self; -} - -<<<<<<< HEAD -- (void)dealloc -{ - [_title release]; - [_message release]; - [_backgroundImage release]; - [_view release]; - [_blocks release]; - [_completionBlocks release]; - [super dealloc]; -======= -- (void)dealloc { - [_title release]; - [_message release]; - [_backgroundImage release]; - [_view release]; - [_blocks release]; - [_messageFont release]; - [_tintColor release]; - [_textColor release]; - [super dealloc]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// -#pragma mark - Public - -<<<<<<< HEAD -- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block -{ - [self addButtonWithTitle:title color:color block:block completion:nil]; -} - -- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block completion:(void (^)())completionBlock -{ - [_blocks addObject:[NSArray arrayWithObjects: - block ? [[block copy] autorelease] : [NSNull null], - title, - color, - nil]]; - [_completionBlocks addObject:[NSArray arrayWithObjects: - completionBlock ? [[completionBlock copy] autorelease] : [NSNull null], - title, - color, - nil]]; -======= -- (void)addButtonWithTitle:(NSString *)title color:(NSString *)color block:(void (^)())block { - [_blocks addObject:[NSArray arrayWithObjects:block ? [[block copy] autorelease] : [NSNull null], title, color, nil]]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"gray" block:block]; -} - -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"black" block:block]; -} - -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block { - [self addButtonWithTitle:title color:@"red" block:block]; -} - -- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString *)identifier block:(void (^)())block { - [self addButtonWithTitle:title color:identifier block:block]; -} - -<<<<<<< HEAD -- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock -{ - [self addButtonWithTitle:title color:@"gray" block:block completion:completionBlock]; -} - -- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock -{ - [self addButtonWithTitle:title color:@"black" block:block completion:completionBlock]; -} - -- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block completion:(void (^)())completionBlock -{ - [self addButtonWithTitle:title color:@"red" block:block completion:completionBlock]; -} - -- (void)addButtonWithTitle:(NSString *)title imageIdentifier:(NSString*)identifier block:(void (^)())block completion:(void (^)())completionBlock { - [self addButtonWithTitle:title color:identifier block:block completion:completionBlock]; -} - -- (void)show -{ - _shown = YES; - - BOOL isSecondButton = NO; - NSUInteger index = 0; - for (NSUInteger i = 0; i < _blocks.count; i++) - { - NSArray *block = [_blocks objectAtIndex:i]; - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width+1)>>1 topCapHeight:0]; - - UIImage *highlightedImage = [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button-highlighted.png", color]]; - - highlightedImage = [highlightedImage stretchableImageWithLeftCapWidth:(int)(highlightedImage.size.width+1)>>1 topCapHeight:0]; - - CGFloat maxHalfWidth = floorf((_view.bounds.size.width-kAlertViewBorder*3)*0.5); - CGFloat width = _view.bounds.size.width-kAlertViewBorder*2; - CGFloat xOffset = kAlertViewBorder; - if (isSecondButton) - { -======= -- (void)show { - _shown = YES; - - BOOL isSecondButton = NO; - NSUInteger index = 0; - for (NSUInteger i = 0; i < _blocks.count; i++) { - NSArray *block = [_blocks objectAtIndex:i]; - NSString *title = [block objectAtIndex:1]; - NSString *color = [block objectAtIndex:2]; - - UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button.png", color]]; - image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width + 1) >> 1 topCapHeight:0]; - - UIImage *highlightedImage = - [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button-highlighted.png", color]]; - - highlightedImage = - [highlightedImage stretchableImageWithLeftCapWidth:(int)(highlightedImage.size.width + 1) >> 1 topCapHeight:0]; - - CGFloat width = _view.bounds.size.width - kAlertViewBorder * 2; - CGFloat xOffset = kAlertViewBorder; - if (_allButtonInLine) { - width = floorf((_view.bounds.size.width - kAlertViewBorder * (_blocks.count + 1)) / _blocks.count); - xOffset = i * width + kAlertViewBorder * (i + 1); - isSecondButton = (i < _blocks.count - 1); - } else { - CGFloat maxHalfWidth = floorf((_view.bounds.size.width - kAlertViewBorder * 3) * 0.5); - if (isSecondButton) { - width = maxHalfWidth; - xOffset = width + kAlertViewBorder * 2; - isSecondButton = NO; - } else if (i + 1 < _blocks.count) { - // In this case there's another button. - // Let's check if they fit on the same line. - CGSize size = [title sizeWithFont:buttonFont - minFontSize:10 - actualFontSize:nil - forWidth:_view.bounds.size.width - kAlertViewBorder * 2 - lineBreakMode:NSLineBreakByClipping]; - - if (size.width < maxHalfWidth - kAlertViewBorder) { - // It might fit. Check the next Button - NSArray *block2 = [_blocks objectAtIndex:i + 1]; - NSString *title2 = [block2 objectAtIndex:1]; - size = [title2 sizeWithFont:buttonFont - minFontSize:10 - actualFontSize:nil - forWidth:_view.bounds.size.width - kAlertViewBorder * 2 - lineBreakMode:NSLineBreakByClipping]; - - if (size.width < maxHalfWidth - kAlertViewBorder) { - // They'll fit! - isSecondButton = YES; // For the next iteration ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - width = maxHalfWidth; - } - } -<<<<<<< HEAD - else if (i + 1 < _blocks.count) - { - // In this case there's another button. - // Let's check if they fit on the same line. - CGSize size; - if (IOS_LESS_THAN_7) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - size = [title sizeWithFont:buttonFont minFontSize:10 actualFontSize:nil forWidth:_view.bounds.size.width-kAlertViewBorder*2 lineBreakMode:NSLineBreakByClipping]; -#pragma clang diagnostic pop - } - else { - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - paragraphStyle.lineBreakMode = NSLineBreakByClipping; - size = [title boundingRectWithSize:CGSizeMake(_view.bounds.size.width-kAlertViewBorder*2, _height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSParagraphStyleAttributeName : paragraphStyle,NSFontAttributeName : buttonFont} context:nil].size; - size = CGSizeMake(ceilf(size.width), ceilf(size.height)); - } - - if (size.width < maxHalfWidth - kAlertViewBorder) - { - // It might fit. Check the next Button - NSArray *block2 = [_blocks objectAtIndex:i+1]; - NSString *title2 = [block2 objectAtIndex:1]; - if (IOS_LESS_THAN_7) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - size = [title2 sizeWithFont:buttonFont minFontSize:10 actualFontSize:nil forWidth:_view.bounds.size.width-kAlertViewBorder*2 lineBreakMode:NSLineBreakByClipping]; -#pragma clang diagnostic pop - } - else { - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - paragraphStyle.lineBreakMode = NSLineBreakByClipping; - size = [title2 boundingRectWithSize:CGSizeMake(_view.bounds.size.width-kAlertViewBorder*2, _height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSParagraphStyleAttributeName : paragraphStyle, NSFontAttributeName : buttonFont} context:nil].size; - size = CGSizeMake(ceilf(size.width), ceilf(size.height)); - } - - if (size.width < maxHalfWidth - kAlertViewBorder) - { - // They'll fit! - isSecondButton = YES; // For the next iteration - width = maxHalfWidth; - } - } - } - else if (_blocks.count == 1) - { - // In this case this is the ony button. We'll size according to the text - CGSize size; - if (IOS_LESS_THAN_7) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - size = [title sizeWithFont:buttonFont minFontSize:10 actualFontSize:nil forWidth:_view.bounds.size.width-kAlertViewBorder*2 lineBreakMode:NSLineBreakByClipping]; -#pragma clang diagnostic pop - } - else { - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - paragraphStyle.lineBreakMode = NSLineBreakByClipping; - size = [title boundingRectWithSize:CGSizeMake(_view.bounds.size.width-kAlertViewBorder*2, _height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSParagraphStyleAttributeName : paragraphStyle, NSFontAttributeName : buttonFont} context:nil].size; - size = CGSizeMake(ceilf(size.width), ceilf(size.height)); - } - - size.width = MAX(size.width, 80); - if (size.width + 2 * kAlertViewBorder < width) - { - width = size.width + 2 * kAlertViewBorder; - xOffset = floorf((_view.bounds.size.width - width) * 0.5); - } - } - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(xOffset, _height, width, kAlertButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; - button.titleLabel.adjustsLetterSpacingToFitWidth = YES; -#pragma clang diagnostic pop - } - else { - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.minimumScaleFactor = 0.1; - } - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kAlertViewButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i+1; - - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) - { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - } - [button setTitleColor:kAlertViewButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kAlertViewButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - [_view addSubview:button]; - - if (!isSecondButton) - _height += kAlertButtonHeight + kAlertViewBorder; - - index++; -======= - } else if (_blocks.count == 1) { - // In this case this is the ony button. We'll size according to the text - CGSize size = [title sizeWithFont:buttonFont - minFontSize:10 - actualFontSize:nil - forWidth:_view.bounds.size.width - kAlertViewBorder * 2 - lineBreakMode:NSLineBreakByClipping]; - - size.width = MAX(size.width, 80); - if (size.width + 2 * kAlertViewBorder < width) { - width = size.width + 2 * kAlertViewBorder; - xOffset = floorf((_view.bounds.size.width - width) * 0.5); - } - } - } - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.frame = CGRectMake(xOffset, _height, width, kAlertButtonHeight); - button.titleLabel.font = buttonFont; - if (IOS_LESS_THAN_6) { -#pragma clan diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - button.titleLabel.minimumFontSize = 10; -#pragma clan diagnostic pop - } else { - button.titleLabel.adjustsFontSizeToFitWidth = YES; - button.titleLabel.adjustsLetterSpacingToFitWidth = YES; - button.titleLabel.minimumScaleFactor = 0.1; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - button.titleLabel.textAlignment = NSTextAlignmentCenter; - button.titleLabel.shadowOffset = kAlertViewButtonShadowOffset; - button.backgroundColor = [UIColor clearColor]; - button.tag = i + 1; - - [button setBackgroundImage:image forState:UIControlStateNormal]; - if (highlightedImage) { - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - } -<<<<<<< HEAD - - - CGRect frame = _view.frame; - frame.origin.y = - _height; - frame.size.height = _height; - _view.frame = frame; - - - UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; - - if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) - modalBackground.image = backgroundlandscape; - else - modalBackground.image = background; - - modalBackground.contentMode = UIViewContentModeScaleToFill; - modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [_view insertSubview:modalBackground atIndex:0]; - [modalBackground release]; - - if (_backgroundImage) - { - [BlockBackground sharedInstance].backgroundImage = _backgroundImage; - [_backgroundImage release]; - _backgroundImage = nil; -======= - [button setTitleColor:kAlertViewButtonTextColor forState:UIControlStateNormal]; - [button setTitleShadowColor:kAlertViewButtonShadowColor forState:UIControlStateNormal]; - [button setTitle:title forState:UIControlStateNormal]; - button.accessibilityLabel = title; - - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - [_view addSubview:button]; - - if (!isSecondButton) _height += kAlertButtonHeight + kAlertViewBorder; - - index++; - } - - //_height += 10; // Margin for the shadow // not sure where this came from, but it's making things look strange (I - // don't see a shadow, either) - if (_height < background.size.height) { - CGFloat offset = background.size.height - _height; - _height = background.size.height; - CGRect frame; - for (NSUInteger i = 0; i < _blocks.count; i++) { - UIButton *btn = (UIButton *)[_view viewWithTag:i + 1]; - frame = btn.frame; - frame.origin.y += offset; - btn.frame = frame; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - } - - // Ragta: aggiungo qua: - CGFloat heightBackground = _height; - UIWindow *parentView = [BlockBackground sharedInstance]; - if (_height > parentView.bounds.size.height) { - CGSize csize = _view.contentSize; - csize.height = _height; - _view.contentSize = csize; - _height = parentView.bounds.size.height; - } - - CGRect frame = _view.frame; - frame.origin.y = -_height; - frame.size.height = _height; - _view.frame = frame; - - // UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; - UIImageView *modalBackground = - [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, heightBackground)]; - - if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) - modalBackground.image = backgroundlandscape; - else - modalBackground.image = background; - - if (_tintColor) { - modalBackground.image = [modalBackground.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; - modalBackground.tintColor = _tintColor; - } - // fine Ragta - - modalBackground.contentMode = UIViewContentModeScaleToFill; - modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [_view insertSubview:modalBackground atIndex:0]; - [modalBackground release]; - - if (_backgroundImage) { - [BlockBackground sharedInstance].backgroundImage = _backgroundImage; - [_backgroundImage release]; - _backgroundImage = nil; - } - - [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; - [[BlockBackground sharedInstance] addToMainWindow:_view]; - - __block CGPoint center = _view.center; - center.y = floorf([BlockBackground sharedInstance].bounds.size.height * 0.5) + kAlertViewBounce; - - _cancelBounce = NO; - - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseOut - animations:^{ - [BlockBackground sharedInstance].alpha = 1.0f; - _view.center = center; - } - completion:^(BOOL finished) { - if (_cancelBounce) return; - -<<<<<<< HEAD -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated -{ - _shown = NO; - - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - // Block execution - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) - { - id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) - { - ((void (^)())obj)(); - } - } - - if (animated) - { - [UIView animateWithDuration:0.1 - delay:0.0 - options:0 - animations:^{ - CGPoint center = _view.center; - center.y += 20; - _view.center = center; - } - completion:^(BOOL finished) { - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseIn - animations:^{ - CGRect frame = _view.frame; - frame.origin.y = -frame.size.height; - _view.frame = frame; - [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; - } - completion:^(BOOL finished) { - - // Completion block - 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 - { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; _view = nil; - [self autorelease]; -======= - [UIView animateWithDuration:0.1 - delay:0.0 - options:0 - animations:^{ - center.y -= kAlertViewBounce; - _view.center = center; - } - completion:^(BOOL finished) { - [[NSNotificationCenter defaultCenter] postNotificationName:@"AlertViewFinishedAnimations" object:self]; - }]; - }]; - - [self retain]; -} - -- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated { - _shown = NO; - - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - if (buttonIndex >= 0 && buttonIndex < [_blocks count]) { - id obj = [[_blocks objectAtIndex:buttonIndex] objectAtIndex:0]; - if (![obj isEqual:[NSNull null]]) { - ((void (^)())obj)(); ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 - } - } - - if (animated) { - [UIView animateWithDuration:0.1 - delay:0.0 - options:0 - animations:^{ - CGPoint center = _view.center; - center.y += 20; - _view.center = center; - } - completion:^(BOOL finished) { - [UIView animateWithDuration:0.4 - delay:0.0 - options:UIViewAnimationOptionCurveEaseIn - animations:^{ - CGRect frame = _view.frame; - frame.origin.y = -frame.size.height; - _view.frame = frame; - [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; - } - completion:^(BOOL finished) { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; - _view = nil; - [self autorelease]; - }]; - }]; - } else { - [[BlockBackground sharedInstance] removeView:_view]; - [_view release]; - _view = nil; - [self autorelease]; - } -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// -#pragma mark - Action - -<<<<<<< HEAD -- (void)buttonClicked:(id)sender -{ - /* Run the button's block */ - NSInteger buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; -======= -- (void)buttonClicked:(id)sender { - /* Run the button's block */ - int buttonIndex = [(UIButton *)sender tag] - 1; - [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; ->>>>>>> 111301187903f7428f6cbcc23db28b269c4ede51 -} - -@end From 8ffb45f282b7da8f744f6398d5cabd834c40ab67 Mon Sep 17 00:00:00 2001 From: Pedro Ventura Date: Fri, 16 Dec 2016 09:23:03 +0100 Subject: [PATCH 32/32] Update version, homepage, author and source properties --- BlockAlertsAnd-ActionSheets.podspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BlockAlertsAnd-ActionSheets.podspec b/BlockAlertsAnd-ActionSheets.podspec index e6dd200..30c3499 100644 --- a/BlockAlertsAnd-ActionSheets.podspec +++ b/BlockAlertsAnd-ActionSheets.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "BlockAlertsAnd-ActionSheets" - s.version = "1.0.10" + s.version = "1.0.11" s.summary = 'Beautifully done UIAlertView and UIActionSheet replacements inspired by TweetBot.' - s.homepage = "https://github.com/taymer/BlockAlertsAnd-ActionSheets" + s.homepage = "https://github.com/pventura1976/BlockAlertsAnd-ActionSheets" s.license = 'MIT' - s.author = { 'Gustavo Ambrozio' => '', "Barrett Jacobsen" => "admin@barrettj.com", "Jose Santiago Jr" => '', 'Taymer Ragazzini' => 'tragazzini@gmail.com' } - s.source = { :git => 'https://github.com/taymer/BlockAlertsAnd-ActionSheets.git', :tag => "#{s.version}" } + s.author = { 'Gustavo Ambrozio' => '', "Barrett Jacobsen" => "admin@barrettj.com", "Jose Santiago Jr" => '', 'Taymer Ragazzini' => 'tragazzini@gmail.com', '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.resources = "BlockAlertsDemo/images/button*.png", "BlockAlertsDemo/images/ActionSheet/*.png", "BlockAlertsDemo/images/AlertView/*.png"