diff --git a/SCLAlertView-Objective-C.podspec b/SCLAlertView-Objective-C.podspec index 5388229..540237a 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.3.4" + spec.version = "0.3.5" 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" diff --git a/SCLAlertView/SCLAlertView.m b/SCLAlertView/SCLAlertView.m index 0e35d59..bd3b424 100755 --- a/SCLAlertView/SCLAlertView.m +++ b/SCLAlertView/SCLAlertView.m @@ -7,7 +7,6 @@ // #import "SCLAlertView.h" -#import "SCLButton.h" #import "SCLAlertViewResponder.h" #import "SCLAlertViewStyleKit.h" #import "UIImage+ImageEffects.h" @@ -18,6 +17,12 @@ green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \ blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] +#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) +#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending) +#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) +#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) +#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) + #define KEYBOARD_HEIGHT 80 #define PREDICTION_BAR_HEIGHT 40 @@ -126,11 +131,15 @@ - (instancetype)init // View text _viewText.editable = NO; _viewText.allowsEditingTextAttributes = YES; - _viewText.textContainerInset = UIEdgeInsetsZero; - _viewText.textContainer.lineFragmentPadding = 0; _viewText.textAlignment = NSTextAlignmentCenter; _viewText.font = [UIFont fontWithName:kDefaultFont size:14.0f]; + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) + { + _viewText.textContainerInset = UIEdgeInsetsZero; + _viewText.textContainer.lineFragmentPadding = 0; + } + // Colors _contentView.backgroundColor = [UIColor whiteColor]; _labelTitle.textColor = UIColorFromRGB(0x4D4D4D); @@ -169,8 +178,7 @@ -(void)viewWillLayoutSubviews CGSize sz = [UIScreen mainScreen].bounds.size; - NSString *systemVersion = [[UIDevice currentDevice] systemVersion]; - if ([systemVersion floatValue] < 8.0f) + if (SYSTEM_VERSION_LESS_THAN(@"8.0")) { // iOS versions before 7.0 did not switch the width and height on device roration if UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) @@ -419,7 +427,7 @@ - (void)buttonTapped:(SCLButton *)btn { // If the button has a validation block, and the validation block returns NO, validation // failed, so we should bail. - if (btn.validationBlock && btn.validationBlock() == NO) { + if (btn.validationBlock && !btn.validationBlock()) { return; } if (btn.actionType == Block) @@ -526,7 +534,7 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag CGSize sz = CGSizeMake(kWindowWidth - 24.0f, 90.0f); NSDictionary *attr = @{NSFontAttributeName:self.viewText.font}; - if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { NSString *str = subTitle; CGRect r = [str boundingRectWithSize:sz options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil]; @@ -541,7 +549,7 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag { NSAttributedString *str =[[NSAttributedString alloc] initWithString:subTitle attributes:attr]; CGRect r = [str boundingRectWithSize:sz options:NSStringDrawingUsesLineFragmentOrigin context:nil]; - CGFloat ht = ceil(r.size.height); + CGFloat ht = ceil(r.size.height) + 10; if (ht < kTextHeight) { kWindowHeight -= (kTextHeight - ht); diff --git a/SCLAlertView/SCLButton.m b/SCLAlertView/SCLButton.m index 572c06a..3bcc819 100644 --- a/SCLAlertView/SCLButton.m +++ b/SCLAlertView/SCLButton.m @@ -38,15 +38,8 @@ - (id)initWithFrame:(CGRect)frame } - (void)setHighlighted:(BOOL)highlighted -{ - if(highlighted) - { - self.backgroundColor = [self darkerColorForColor:_defaultBackgroundColor]; - } - else - { - self.backgroundColor = _defaultBackgroundColor; - } +{ + self.backgroundColor = (highlighted) ? [self darkerColorForColor:_defaultBackgroundColor] : _defaultBackgroundColor; [super setHighlighted:highlighted]; } @@ -59,17 +52,17 @@ - (void)setDefaultBackgroundColor:(UIColor *)defaultBackgroundColor - (void)parseConfig:(NSDictionary *)buttonConfig { - if ([buttonConfig objectForKey:@"backgroundColor"]) + if (buttonConfig[@"backgroundColor"]) { - self.defaultBackgroundColor = [buttonConfig objectForKey:@"backgroundColor"]; + self.defaultBackgroundColor = buttonConfig[@"backgroundColor"]; } - if ([buttonConfig objectForKey:@"borderColor"]) + if (buttonConfig[@"borderColor"]) { - self.layer.borderColor = ((UIColor*)[buttonConfig objectForKey:@"borderColor"]).CGColor; + self.layer.borderColor = ((UIColor*)buttonConfig[@"borderColor"]).CGColor; } - if ([buttonConfig objectForKey:@"textColor"]) + if (buttonConfig[@"textColor"]) { - [self setTitleColor:[buttonConfig objectForKey:@"textColor"] forState:UIControlStateNormal]; + [self setTitleColor:buttonConfig[@"textColor"] forState:UIControlStateNormal]; } } diff --git a/SCLAlertViewExample/ViewController.m b/SCLAlertViewExample/ViewController.m index 4c7397f..89913d1 100644 --- a/SCLAlertViewExample/ViewController.m +++ b/SCLAlertViewExample/ViewController.m @@ -46,9 +46,9 @@ - (IBAction)showSuccess:(id)sender { NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init]; - [buttonConfig setObject:[UIColor whiteColor] forKey:@"backgroundColor"]; - [buttonConfig setObject:[UIColor blackColor] forKey:@"textColor"]; - [buttonConfig setObject:[UIColor greenColor] forKey:@"borderColor"]; + buttonConfig[@"backgroundColor"] = [UIColor whiteColor]; + buttonConfig[@"textColor"] = [UIColor blackColor]; + buttonConfig[@"borderColor"] = [UIColor greenColor]; return buttonConfig; }; @@ -133,8 +133,8 @@ - (IBAction)showAdvanced:(id)sender { NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init]; - [buttonConfig setObject:[UIColor greenColor] forKey:@"backgroundColor"]; - [buttonConfig setObject:[UIColor blackColor] forKey:@"textColor"]; + buttonConfig[@"backgroundColor"] = [UIColor greenColor]; + buttonConfig[@"textColor"] = [UIColor blackColor]; return buttonConfig; };