From 7df190bf6d368dc90f32dccb712e3748d6aaf821 Mon Sep 17 00:00:00 2001 From: Diogo Autilio Date: Tue, 21 Oct 2014 21:25:45 -0200 Subject: [PATCH 1/4] Update example using dismiss block Update readme using dismiss block --- README.md | 9 +++++++++ SCLAlertViewExample/ViewController.m | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index 365fb61..4246c05 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,15 @@ alert.hideAnimationType = SlideOutToBottom; alert.soundURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/right_answer.mp3", [[NSBundle mainBundle] resourcePath]]]; ``` +###Helpers +``` +```Objective-C +//Receiving information that SCLAlertView is dismissed +[alert alertIsDismissed:^{ + NSLog(@"SCLAlertView dismissed!"); +}]; +``` + ####Alert View Styles ```Objective-C typedef NS_ENUM(NSInteger, SCLAlertViewStyle) diff --git a/SCLAlertViewExample/ViewController.m b/SCLAlertViewExample/ViewController.m index 949666d..e3fa447 100644 --- a/SCLAlertViewExample/ViewController.m +++ b/SCLAlertViewExample/ViewController.m @@ -78,6 +78,10 @@ - (IBAction)showInfo:(id)sender alert.shouldDismissOnTapOutside = YES; + [alert alertIsDismissed:^{ + NSLog(@"SCLAlertView dismissed!"); + }]; + [alert showInfo:self title:kInfoTitle subTitle:kSubtitle closeButtonTitle:kButtonTitle duration:0.0f]; } From 5c2ddf642cb9c734cf2e3a8b04bc91303a24ed9c Mon Sep 17 00:00:00 2001 From: Diogo Autilio Date: Wed, 22 Oct 2014 16:39:05 -0200 Subject: [PATCH 2/4] Add completeButtonFormatBlock --- SCLAlertView/SCLAlertView.h | 7 +++++++ SCLAlertView/SCLAlertView.m | 21 +++++++++++++++++++++ SCLAlertView/SCLButton.h | 8 ++++++++ SCLAlertViewExample/ViewController.m | 10 ++++++++++ 4 files changed, 46 insertions(+) diff --git a/SCLAlertView/SCLAlertView.h b/SCLAlertView/SCLAlertView.h index dd0a2d3..d1e8abe 100755 --- a/SCLAlertView/SCLAlertView.h +++ b/SCLAlertView/SCLAlertView.h @@ -74,6 +74,13 @@ typedef NS_ENUM(NSInteger, SCLAlertViewAnimation) */ @property (nonatomic, copy) SCLAttributedFormatBlock attributedFormatBlock; +/** Set button format block. + * + * Holds the button format block. + * Support keys : backgroundColor, textColor + */ +@property (nonatomic, copy) CompleteButtonFormatBlock completeButtonFormatBlock; + /** Hide animation type * * Holds the hide animation type. diff --git a/SCLAlertView/SCLAlertView.m b/SCLAlertView/SCLAlertView.m index f07ae91..8fafe73 100755 --- a/SCLAlertView/SCLAlertView.m +++ b/SCLAlertView/SCLAlertView.m @@ -341,6 +341,12 @@ - (SCLButton *)addButton:(NSString *)title - (SCLButton *)addDoneButtonWithTitle:(NSString *)title { SCLButton *btn = [self addButton:title]; + + if (_completeButtonFormatBlock != nil) + { + btn.completeButtonFormatBlock = _completeButtonFormatBlock; + } + [btn addTarget:self action:@selector(hideView) forControlEvents:UIControlEventTouchUpInside]; return btn; @@ -521,6 +527,21 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag for (SCLButton *btn in _buttons) { + if (btn.completeButtonFormatBlock != nil) + { + NSDictionary *buttonConfig = btn.completeButtonFormatBlock(); + + if ([buttonConfig objectForKey:@"backgroundColor"]) + { + viewColor = [buttonConfig objectForKey:@"backgroundColor"]; + [btn setBackgroundColor:viewColor]; + } + if ([buttonConfig objectForKey:@"textColor"]) + { + [btn setTitleColor:[buttonConfig objectForKey:@"textColor"] forState:UIControlStateNormal]; + } + } + btn.defaultBackgroundColor = viewColor; if (style == Warning) diff --git a/SCLAlertView/SCLButton.h b/SCLAlertView/SCLButton.h index 3fd0afc..f39e442 100644 --- a/SCLAlertView/SCLButton.h +++ b/SCLAlertView/SCLButton.h @@ -12,6 +12,7 @@ typedef void (^ActionBlock)(void); typedef BOOL (^ValidationBlock)(void); +typedef NSDictionary* (^CompleteButtonFormatBlock)(void); // Action Types typedef NS_ENUM(NSInteger, SCLActionType) @@ -39,6 +40,13 @@ typedef NS_ENUM(NSInteger, SCLActionType) */ @property (nonatomic, copy) ValidationBlock validationBlock; +/** Set button format block. + * + * Holds the button format block. + * Support keys : backgroundColor, textColor + */ +@property (nonatomic, copy) CompleteButtonFormatBlock completeButtonFormatBlock; + /** TODO * * TODO diff --git a/SCLAlertViewExample/ViewController.m b/SCLAlertViewExample/ViewController.m index e3fa447..e874401 100644 --- a/SCLAlertViewExample/ViewController.m +++ b/SCLAlertViewExample/ViewController.m @@ -114,6 +114,16 @@ - (IBAction)showAdvanced:(id)sender NSLog(@"Text value: %@", textField.text); }]; + alert.completeButtonFormatBlock = ^NSDictionary* (void) + { + NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init]; + + [buttonConfig setObject:[UIColor greenColor] forKey:@"backgroundColor"]; + [buttonConfig setObject:[UIColor purpleColor] forKey:@"textColor"]; + + return buttonConfig; + }; + alert.attributedFormatBlock = ^NSAttributedString* (NSString *value) { NSMutableAttributedString *subTitle = [[NSMutableAttributedString alloc]initWithString:value]; From e94519801f88159136a0d20a6137a033ed8f8516 Mon Sep 17 00:00:00 2001 From: Diogo Autilio Date: Wed, 22 Oct 2014 16:45:42 -0200 Subject: [PATCH 3/4] Fixed iOS 6.1 crash related to boundingRectWithSize. Thanks @rando128 --- SCLAlertView/SCLAlertView.m | 27 +++++++++++++++++++++------ SCLAlertViewExample/ViewController.m | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/SCLAlertView/SCLAlertView.m b/SCLAlertView/SCLAlertView.m index 8fafe73..7d45505 100755 --- a/SCLAlertView/SCLAlertView.m +++ b/SCLAlertView/SCLAlertView.m @@ -485,15 +485,30 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag } // Adjust text view size, if necessary - NSString *str = subTitle; CGSize sz = CGSizeMake(kWindowWidth - 24.0f, 90.0f); NSDictionary *attr = @{NSFontAttributeName:self.viewText.font}; - CGRect r = [str boundingRectWithSize:sz options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil]; - CGFloat ht = ceil(r.size.height) + 10; - if (ht < kTextHeight) + + if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) + { + NSString *str = subTitle; + CGRect r = [str boundingRectWithSize:sz options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil]; + CGFloat ht = ceil(r.size.height) + 10; + if (ht < kTextHeight) + { + kWindowHeight -= (kTextHeight - ht); + kTextHeight = ht; + } + } + else { - kWindowHeight -= (kTextHeight - ht); - kTextHeight = ht; + NSAttributedString *str =[[NSAttributedString alloc] initWithString:subTitle]; + CGRect r = [str boundingRectWithSize:sz options:NSStringDrawingUsesLineFragmentOrigin context:nil]; + CGFloat ht = ceil(r.size.height) + 10; + if (ht < kTextHeight) + { + kWindowHeight -= (kTextHeight - ht); + kTextHeight = ht; + } } } diff --git a/SCLAlertViewExample/ViewController.m b/SCLAlertViewExample/ViewController.m index e874401..a0348ce 100644 --- a/SCLAlertViewExample/ViewController.m +++ b/SCLAlertViewExample/ViewController.m @@ -119,7 +119,7 @@ - (IBAction)showAdvanced:(id)sender NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init]; [buttonConfig setObject:[UIColor greenColor] forKey:@"backgroundColor"]; - [buttonConfig setObject:[UIColor purpleColor] forKey:@"textColor"]; + [buttonConfig setObject:[UIColor blackColor] forKey:@"textColor"]; return buttonConfig; }; From e611881257a3eb597037754bfc54593d7eb2c959 Mon Sep 17 00:00:00 2001 From: Diogo Autilio Date: Wed, 22 Oct 2014 16:47:08 -0200 Subject: [PATCH 4/4] Bump version --- SCLAlertView-Objective-C.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SCLAlertView-Objective-C.podspec b/SCLAlertView-Objective-C.podspec index 893d771..7b12063 100644 --- a/SCLAlertView-Objective-C.podspec +++ b/SCLAlertView-Objective-C.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "SCLAlertView-Objective-C" - spec.version = "0.2.3" + spec.version = "0.2.4" spec.summary = "Beautiful animated Alert View. Written in Swift but ported to Objective-C" spec.homepage = "https://github.com/dogo/SCLAlertView" spec.screenshots = "https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot.png", "https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot2.png" @@ -10,7 +10,7 @@ Pod::Spec.new do |spec| spec.social_media_url = "http://twitter.com/di_autilio" spec.platform = :ios spec.ios.deployment_target = '7.0' - spec.source = { :git => "https://github.com/dogo/SCLAlertView.git", :tag => "0.2.3" } + spec.source = { :git => "https://github.com/dogo/SCLAlertView.git", :tag => "0.2.4" } spec.source_files = "SCLAlertView/*" spec.requires_arc = true end