From 52b605f4493146519da3a8856f940c21932860d8 Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Wed, 23 Jul 2014 14:00:55 +0200 Subject: [PATCH 01/14] Added first textfield implementation Text color and background color if fixed on black and white. --- SIAlertView/SIAlertView.h | 3 +- SIAlertView/SIAlertView.m | 304 ++++++++++++++++++++++++-------------- 2 files changed, 196 insertions(+), 111 deletions(-) diff --git a/SIAlertView/SIAlertView.h b/SIAlertView/SIAlertView.h index d95c697..e19fec5 100644 --- a/SIAlertView/SIAlertView.h +++ b/SIAlertView/SIAlertView.h @@ -44,7 +44,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView); @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *message; - +@property (nonatomic, strong) NSMutableArray *textFields; @property (nonatomic, assign) SIAlertViewTransitionStyle transitionStyle; // default is SIAlertViewTransitionStyleSlideFromBottom @property (nonatomic, assign) SIAlertViewBackgroundStyle backgroundStyle; // default is SIAlertViewButtonTypeGradient @property (nonatomic, assign) SIAlertViewButtonsListStyle buttonsListStyle; // default is SIAlertViewButtonsListStyleNormal @@ -76,6 +76,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView); - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message; - (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type handler:(SIAlertViewHandler)handler; +-(void)addTextFieldWithPlaceHolder:(NSString *)placeholder andText:(NSString *)text; - (void)show; - (void)dismissAnimated:(BOOL)animated; diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 511121a..8241abf 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -25,6 +25,7 @@ #define CONTENT_PADDING_TOP 12 #define CONTENT_PADDING_BOTTOM 10 #define BUTTON_HEIGHT 44 +#define TEXTFIELD_HEIGHT 44 #define CONTAINER_WIDTH 300 const UIWindowLevel UIWindowLevelSIAlert = 1996.0; // don't overlap system's alert @@ -38,8 +39,8 @@ static SIAlertView *__si_alert_current_view; @interface SIAlertView () - @property (nonatomic, strong) NSMutableArray *items; +@property (nonatomic, strong) NSMutableArray *textFieldsItems; @property (nonatomic, weak) UIWindow *oldKeyWindow; @property (nonatomic, strong) UIWindow *alertWindow; #ifdef __IPHONE_7_0 @@ -107,7 +108,7 @@ - (void)drawRect:(CGRect)rect 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); CGFloat radius = MIN(self.bounds.size.width, self.bounds.size.height) ; CGContextDrawRadialGradient (context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation); @@ -139,6 +140,18 @@ @implementation SIAlertItem @end +#pragma mark - SITextItem +@interface SITextItem : NSObject + +@property (nonatomic, copy) NSString *placeholder; +@property (nonatomic, copy) NSString *text; + +@end + +@implementation SITextItem + +@end + #pragma mark - SIAlertViewController @interface SIAlertViewController : UIViewController @@ -229,12 +242,11 @@ - (BOOL)prefersStatusBarHidden #pragma mark - SIAlert @implementation SIAlertView - + (void)initialize { if (self != [SIAlertView class]) return; - + SIAlertView *appearance = [self appearance]; appearance.viewBackgroundColor = [UIColor whiteColor]; appearance.titleColor = [UIColor blackColor]; @@ -251,19 +263,20 @@ + (void)initialize - (id)init { - return [self initWithTitle:nil andMessage:nil]; + return [self initWithTitle:nil andMessage:nil]; } - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message { - self = [super init]; - if (self) { - _title = title; + self = [super init]; + if (self) { + _title = title; _message = message; _enabledParallaxEffect = YES; - self.items = [[NSMutableArray alloc] init]; - } - return self; + self.items = [[NSMutableArray alloc] init]; + self.textFieldsItems = [[NSMutableArray alloc] init]; + } + return self; } #pragma mark - Class methods @@ -332,12 +345,12 @@ + (void)hideBackgroundAnimated:(BOOL)animated - (void)setTitle:(NSString *)title { _title = title; - [self invalidateLayout]; + [self invalidateLayout]; } - (void)setMessage:(NSString *)message { - _message = message; + _message = message; [self invalidateLayout]; } @@ -346,18 +359,30 @@ - (void)setMessage:(NSString *)message - (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type handler:(SIAlertViewHandler)handler { SIAlertItem *item = [[SIAlertItem alloc] init]; - item.title = title; - item.type = type; - item.action = handler; - [self.items addObject:item]; + item.title = title; + item.type = type; + item.action = handler; + [self.items addObject:item]; } + +-(void)addTextFieldWithPlaceHolder:(NSString *)placeholder andText:(NSString *)text +{ + SITextItem *item = [[SITextItem alloc] init]; + item.placeholder = placeholder; + item.text = text; + [self.textFieldsItems addObject:item]; + +} + + + - (void)show { if (self.isVisible) { return; } - + self.oldKeyWindow = [[UIApplication sharedApplication] keyWindow]; #ifdef __IPHONE_7_0 if ([self.oldKeyWindow respondsToSelector:@selector(setTintAdjustmentMode:)]) { // for iOS 7 @@ -369,33 +394,33 @@ - (void)show if (![[SIAlertView sharedQueue] containsObject:self]) { [[SIAlertView sharedQueue] addObject:self]; } - + if ([SIAlertView isAnimating]) { return; // wait for next turn } - + if ([SIAlertView currentAlertView].isVisible) { SIAlertView *alert = [SIAlertView currentAlertView]; [alert dismissAnimated:YES cleanup:NO]; return; } - + if (self.willShowHandler) { self.willShowHandler(self); } [[NSNotificationCenter defaultCenter] postNotificationName:SIAlertViewWillShowNotification object:self userInfo:nil]; - + self.visible = YES; - + [SIAlertView setAnimating:YES]; [SIAlertView setCurrentAlertView:self]; - + // transition background [SIAlertView showBackground]; - + SIAlertViewController *viewController = [[SIAlertViewController alloc] initWithNibName:nil bundle:nil]; viewController.alertView = self; - + if (!self.alertWindow) { UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; window.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; @@ -405,20 +430,20 @@ - (void)show self.alertWindow = window; } [self.alertWindow makeKeyAndVisible]; - + [self validateLayout]; - + [self transitionInCompletion:^{ if (self.didShowHandler) { self.didShowHandler(self); } [[NSNotificationCenter defaultCenter] postNotificationName:SIAlertViewDidShowNotification object:self userInfo:nil]; - #ifdef __IPHONE_7_0 +#ifdef __IPHONE_7_0 [self addParallaxEffect]; - #endif - +#endif + [SIAlertView setAnimating:NO]; - + NSInteger index = [[SIAlertView sharedQueue] indexOfObject:self]; if (index < [SIAlertView sharedQueue].count - 1) { [self dismissAnimated:YES cleanup:NO]; // dismiss to show next alert view @@ -434,48 +459,48 @@ - (void)dismissAnimated:(BOOL)animated - (void)dismissAnimated:(BOOL)animated cleanup:(BOOL)cleanup { BOOL isVisible = self.isVisible; - + if (isVisible) { if (self.willDismissHandler) { self.willDismissHandler(self); } [[NSNotificationCenter defaultCenter] postNotificationName:SIAlertViewWillDismissNotification object:self userInfo:nil]; - #ifdef __IPHONE_7_0 - [self removeParallaxEffect]; - #endif +#ifdef __IPHONE_7_0 + [self removeParallaxEffect]; +#endif } - + void (^dismissComplete)(void) = ^{ self.visible = NO; - + [self teardown]; - + [SIAlertView setCurrentAlertView:nil]; - + SIAlertView *nextAlertView; NSInteger index = [[SIAlertView sharedQueue] indexOfObject:self]; if (index != NSNotFound && index < [SIAlertView sharedQueue].count - 1) { nextAlertView = [SIAlertView sharedQueue][index + 1]; } - + if (cleanup) { [[SIAlertView sharedQueue] removeObject:self]; } - + [SIAlertView setAnimating:NO]; - + if (isVisible) { if (self.didDismissHandler) { self.didDismissHandler(self); } [[NSNotificationCenter defaultCenter] postNotificationName:SIAlertViewDidDismissNotification object:self userInfo:nil]; } - + // check if we should show next alert if (!isVisible) { return; } - + if (nextAlertView) { [nextAlertView show]; } else { @@ -486,23 +511,23 @@ - (void)dismissAnimated:(BOOL)animated cleanup:(BOOL)cleanup } } }; - + if (animated && isVisible) { [SIAlertView setAnimating:YES]; [self transitionOutCompletion:dismissComplete]; - + if ([SIAlertView sharedQueue].count == 1) { [SIAlertView hideBackgroundAnimated:YES]; } - + } else { dismissComplete(); - + if ([SIAlertView sharedQueue].count == 0) { [SIAlertView hideBackgroundAnimated:YES]; } } - + UIWindow *window = self.oldKeyWindow; #ifdef __IPHONE_7_0 if ([window respondsToSelector:@selector(setTintAdjustmentMode:)]) { @@ -659,7 +684,7 @@ - (void)transitionOutCompletion:(void(^)(void))completion animation.delegate = self; [animation setValue:completion forKey:@"handler"]; [self.containerView.layer addAnimation:animation forKey:@"bounce"]; - + self.containerView.transform = CGAffineTransformMakeScale(0.01, 0.01); } break; @@ -715,21 +740,21 @@ - (void)validateLayout #if DEBUG_LAYOUT NSLog(@"%@, %@", self, NSStringFromSelector(_cmd)); #endif - + CGFloat height = [self preferredHeight]; CGFloat left = (self.bounds.size.width - CONTAINER_WIDTH) * 0.5; CGFloat top = (self.bounds.size.height - height) * 0.5; self.containerView.transform = CGAffineTransformIdentity; self.containerView.frame = CGRectMake(left, top, CONTAINER_WIDTH, height); self.containerView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.containerView.bounds cornerRadius:self.containerView.layer.cornerRadius].CGPath; - + CGFloat y = CONTENT_PADDING_TOP; - if (self.titleLabel) { + if (self.titleLabel) { self.titleLabel.text = self.title; CGFloat height = [self heightForTitleLabel]; self.titleLabel.frame = CGRectMake(CONTENT_PADDING_LEFT, y, self.containerView.bounds.size.width - CONTENT_PADDING_LEFT * 2, height); y += height; - } + } if (self.messageLabel) { if (y > CONTENT_PADDING_TOP) { y += GAP; @@ -739,6 +764,20 @@ - (void)validateLayout self.messageLabel.frame = CGRectMake(CONTENT_PADDING_LEFT, y, self.containerView.bounds.size.width - CONTENT_PADDING_LEFT * 2, height); y += height; } + + + if(self.textFields.count > 0) { + if (y > CONTENT_PADDING_TOP) { + y += GAP; + } + for (NSUInteger i = 0; i < self.textFields.count; i++) { + UITextField * textField = self.textFields[i]; + [textField setFrame:CGRectMake(CONTENT_PADDING_LEFT, y, (CONTAINER_WIDTH-(CONTENT_PADDING_LEFT*2)), TEXTFIELD_HEIGHT)]; + y += (TEXTFIELD_HEIGHT+GAP); + } + + } + if (self.items.count > 0) { if (y > CONTENT_PADDING_TOP) { y += GAP; @@ -764,20 +803,35 @@ - (void)validateLayout } } } + + + } - (CGFloat)preferredHeight { - CGFloat height = CONTENT_PADDING_TOP; - if (self.title) { - height += [self heightForTitleLabel]; - } + CGFloat height = CONTENT_PADDING_TOP; + if (self.title) { + height += [self heightForTitleLabel]; + } if (self.message) { if (height > CONTENT_PADDING_TOP) { height += GAP; } height += [self heightForMessageLabel]; } + + if(self.textFields.count > 0) { + if (height > CONTENT_PADDING_TOP) { + height += GAP; + } + for (NSUInteger i = 0; i < self.textFields.count; i++) { + + height += (TEXTFIELD_HEIGHT+GAP); + } + + } + if (self.items.count > 0) { if (height > CONTENT_PADDING_TOP) { height += GAP; @@ -792,7 +846,7 @@ - (CGFloat)preferredHeight } } height += CONTENT_PADDING_BOTTOM; - return height; + return height; } - (CGFloat)heightForTitleLabel @@ -803,7 +857,7 @@ - (CGFloat)heightForTitleLabel #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0 self.titleLabel.font.pointSize * self.titleLabel.minimumScaleFactor #else - self.titleLabel.minimumFontSize + self.titleLabel.minimumFontSize #endif actualFontSize:nil forWidth:CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2 @@ -833,6 +887,7 @@ - (void)setup [self setupContainerView]; [self updateTitleLabel]; [self updateMessageLabel]; + [self setupTextFields]; [self setupButtons]; [self invalidateLayout]; } @@ -862,12 +917,12 @@ - (void)setupContainerView - (void)updateTitleLabel { - if (self.title) { - if (!self.titleLabel) { - self.titleLabel = [[UILabel alloc] initWithFrame:self.bounds]; - self.titleLabel.textAlignment = NSTextAlignmentCenter; + if (self.title) { + if (!self.titleLabel) { + self.titleLabel = [[UILabel alloc] initWithFrame:self.bounds]; + self.titleLabel.textAlignment = NSTextAlignmentCenter; self.titleLabel.backgroundColor = [UIColor clearColor]; - self.titleLabel.font = self.titleFont; + self.titleLabel.font = self.titleFont; self.titleLabel.textColor = self.titleColor; self.titleLabel.adjustsFontSizeToFitWidth = YES; #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0 @@ -875,16 +930,16 @@ - (void)updateTitleLabel #else self.titleLabel.minimumFontSize = self.titleLabel.font.pointSize * 0.75; #endif - [self.containerView addSubview:self.titleLabel]; + [self.containerView addSubview:self.titleLabel]; #if DEBUG_LAYOUT self.titleLabel.backgroundColor = [UIColor redColor]; #endif - } - self.titleLabel.text = self.title; - } else { - [self.titleLabel removeFromSuperview]; - self.titleLabel = nil; - } + } + self.titleLabel.text = self.title; + } else { + [self.titleLabel removeFromSuperview]; + self.titleLabel = nil; + } [self invalidateLayout]; } @@ -911,6 +966,34 @@ - (void)updateMessageLabel [self invalidateLayout]; } +- (void)setupTextFields +{ + self.textFields = [[NSMutableArray alloc] initWithCapacity:self.textFieldsItems.count]; + for (NSUInteger i = 0; i < self.textFieldsItems.count; i++) { + UITextField *textField = [self textFieldForItemIndex:i]; + [self.textFields addObject:textField]; + [self.containerView addSubview:textField]; + } +} + +- (UITextField *)textFieldForItemIndex:(NSUInteger)index +{ SITextItem *item = self.textFieldsItems[index]; + UITextField * textField = [[UITextField alloc] init]; + textField.backgroundColor = [UIColor whiteColor]; + textField.placeholder = item.placeholder; + + textField.text = item.text; + + textField.borderStyle=UITextBorderStyleRoundedRect; + textField.autocorrectionType=UITextAutocorrectionTypeNo; + textField.autocapitalizationType=UITextAutocapitalizationTypeNone; + textField.keyboardType=UIKeyboardTypeEmailAddress; + textField.returnKeyType=UIReturnKeyDone; + textField.clearButtonMode=UITextFieldViewModeWhileEditing; + + return textField; +} + - (void)setupButtons { self.buttons = [[NSMutableArray alloc] initWithCapacity:self.items.count]; @@ -924,43 +1007,43 @@ - (void)setupButtons - (UIButton *)buttonForItemIndex:(NSUInteger)index { SIAlertItem *item = self.items[index]; - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.tag = index; - button.autoresizingMask = UIViewAutoresizingFlexibleWidth; + UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; + button.tag = index; + button.autoresizingMask = UIViewAutoresizingFlexibleWidth; button.titleLabel.font = self.buttonFont; - [button setTitle:item.title forState:UIControlStateNormal]; - UIImage *normalImage = nil; - UIImage *highlightedImage = nil; - switch (item.type) { - case SIAlertViewButtonTypeCancel: - normalImage = [UIImage imageNamed:@"SIAlertView.bundle/button-cancel"]; - highlightedImage = [UIImage imageNamed:@"SIAlertView.bundle/button-cancel-d"]; - [button setTitleColor:self.cancelButtonColor forState:UIControlStateNormal]; + [button setTitle:item.title forState:UIControlStateNormal]; + UIImage *normalImage = nil; + UIImage *highlightedImage = nil; + switch (item.type) { + case SIAlertViewButtonTypeCancel: + normalImage = [UIImage imageNamed:@"SIAlertView.bundle/button-cancel"]; + highlightedImage = [UIImage imageNamed:@"SIAlertView.bundle/button-cancel-d"]; + [button setTitleColor:self.cancelButtonColor forState:UIControlStateNormal]; [button setTitleColor:[self.cancelButtonColor colorWithAlphaComponent:0.8] forState:UIControlStateHighlighted]; - break; - case SIAlertViewButtonTypeDestructive: - normalImage = [UIImage imageNamed:@"SIAlertView.bundle/button-destructive"]; - highlightedImage = [UIImage imageNamed:@"SIAlertView.bundle/button-destructive-d"]; + break; + case SIAlertViewButtonTypeDestructive: + normalImage = [UIImage imageNamed:@"SIAlertView.bundle/button-destructive"]; + highlightedImage = [UIImage imageNamed:@"SIAlertView.bundle/button-destructive-d"]; [button setTitleColor:self.destructiveButtonColor forState:UIControlStateNormal]; [button setTitleColor:[self.destructiveButtonColor colorWithAlphaComponent:0.8] forState:UIControlStateHighlighted]; - break; - case SIAlertViewButtonTypeDefault: - default: - normalImage = [UIImage imageNamed:@"SIAlertView.bundle/button-default"]; - highlightedImage = [UIImage imageNamed:@"SIAlertView.bundle/button-default-d"]; - [button setTitleColor:self.buttonColor forState:UIControlStateNormal]; + break; + case SIAlertViewButtonTypeDefault: + default: + normalImage = [UIImage imageNamed:@"SIAlertView.bundle/button-default"]; + highlightedImage = [UIImage imageNamed:@"SIAlertView.bundle/button-default-d"]; + [button setTitleColor:self.buttonColor forState:UIControlStateNormal]; [button setTitleColor:[self.buttonColor colorWithAlphaComponent:0.8] forState:UIControlStateHighlighted]; - break; - } - CGFloat hInset = floorf(normalImage.size.width / 2); - CGFloat vInset = floorf(normalImage.size.height / 2); - UIEdgeInsets insets = UIEdgeInsetsMake(vInset, hInset, vInset, hInset); - normalImage = [normalImage resizableImageWithCapInsets:insets]; - highlightedImage = [highlightedImage resizableImageWithCapInsets:insets]; - [button setBackgroundImage:normalImage forState:UIControlStateNormal]; - [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; - [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; - + break; + } + CGFloat hInset = floorf(normalImage.size.width / 2); + CGFloat vInset = floorf(normalImage.size.height / 2); + UIEdgeInsets insets = UIEdgeInsetsMake(vInset, hInset, vInset, hInset); + normalImage = [normalImage resizableImageWithCapInsets:insets]; + highlightedImage = [highlightedImage resizableImageWithCapInsets:insets]; + [button setBackgroundImage:normalImage forState:UIControlStateNormal]; + [button setBackgroundImage:highlightedImage forState:UIControlStateHighlighted]; + [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; + return button; } @@ -968,12 +1051,12 @@ - (UIButton *)buttonForItemIndex:(NSUInteger)index - (void)buttonAction:(UIButton *)button { - [SIAlertView setAnimating:YES]; // set this flag to YES in order to prevent showing another alert in action block + [SIAlertView setAnimating:YES]; // set this flag to YES in order to prevent showing another alert in action block SIAlertItem *item = self.items[button.tag]; - if (item.action) { - item.action(self); - } - [self dismissAnimated:YES]; + if (item.action) { + item.action(self); + } + [self dismissAnimated:YES]; } #pragma mark - CAAnimation delegate @@ -1135,6 +1218,7 @@ -(void)setColor:(UIColor *)color toButtonsOfType:(SIAlertViewButtonType)type { } } + # pragma mark - # pragma mark Enable parallax effect (iOS7 only) From 4e966997a2c3247846dbe07fcc8ce5fba739bc15 Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Mon, 1 Jun 2015 23:46:24 +0200 Subject: [PATCH 02/14] Fix #101: heightForMessageLabel now uses messageLabel text for height calculation. --- SIAlertView/SIAlertView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 7a67df3..ed9b6e9 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -852,7 +852,7 @@ - (CGFloat)heightForMessageLabel // NSString class method: boundingRectWithSize:options:attributes:context is // available only on ios7.0 sdk. - CGRect rect = [self.titleLabel.text boundingRectWithSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, maxHeight) + CGRect rect = [self.messageLabel.text boundingRectWithSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, maxHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil]; From ec054c8b11408de678963a7e41d2cca421514745 Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Mon, 1 Jun 2015 23:51:59 +0200 Subject: [PATCH 03/14] Allow user to customize the maximumNumberOfLines through a UIAppearance property. --- SIAlertView/SIAlertView.h | 1 + SIAlertView/SIAlertView.m | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/SIAlertView/SIAlertView.h b/SIAlertView/SIAlertView.h index e4d620a..4a51e7e 100644 --- a/SIAlertView/SIAlertView.h +++ b/SIAlertView/SIAlertView.h @@ -69,6 +69,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView); @property (nonatomic, strong) UIColor *destructiveButtonColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; @property (nonatomic, assign) CGFloat cornerRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 2.0 @property (nonatomic, assign) CGFloat shadowRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 8.0 +@property (nonatomic, assign) NSInteger maximumNumberOfLines NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 5 - (void)setDefaultButtonImage:(UIImage *)defaultButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; - (void)setCancelButtonImage:(UIImage *)cancelButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index ed9b6e9..24bb2a5 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -18,7 +18,6 @@ #define DEBUG_LAYOUT 0 #define MESSAGE_MIN_LINE_COUNT 3 -#define MESSAGE_MAX_LINE_COUNT 5 #define GAP 10 #define CANCEL_BUTTON_PADDING_TOP 5 #define CONTENT_PADDING_LEFT 10 @@ -247,6 +246,7 @@ + (void)initialize appearance.destructiveButtonColor = [UIColor whiteColor]; appearance.cornerRadius = 2; appearance.shadowRadius = 8; + appearance.maximumNumberOfLines = 5; } - (id)init @@ -841,7 +841,7 @@ - (CGFloat)heightForMessageLabel { CGFloat minHeight = MESSAGE_MIN_LINE_COUNT * self.messageLabel.font.lineHeight; if (self.messageLabel) { - CGFloat maxHeight = MESSAGE_MAX_LINE_COUNT * self.messageLabel.font.lineHeight; + CGFloat maxHeight = self.maximumNumberOfLines * self.messageLabel.font.lineHeight; #ifdef __IPHONE_7_0 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; @@ -941,7 +941,7 @@ - (void)updateMessageLabel self.messageLabel.backgroundColor = [UIColor clearColor]; self.messageLabel.font = self.messageFont; self.messageLabel.textColor = self.messageColor; - self.messageLabel.numberOfLines = MESSAGE_MAX_LINE_COUNT; + self.messageLabel.numberOfLines = self.maximumNumberOfLines; [self.containerView addSubview:self.messageLabel]; #if DEBUG_LAYOUT self.messageLabel.backgroundColor = [UIColor redColor]; From 0b200e7338dfcf22eb390231c35a6eea841dc5fa Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Tue, 2 Jun 2015 00:26:31 +0200 Subject: [PATCH 04/14] Fix 101: MessageLabel uses messageLabel font for calculation. --- SIAlertView/SIAlertView.m | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 24bb2a5..eab7ab4 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -839,17 +839,14 @@ - (CGFloat)heightForTitleLabel - (CGFloat)heightForMessageLabel { - CGFloat minHeight = MESSAGE_MIN_LINE_COUNT * self.messageLabel.font.lineHeight; + CGFloat minHeight = ceilf(MESSAGE_MIN_LINE_COUNT * self.messageLabel.font.lineHeight); if (self.messageLabel) { - CGFloat maxHeight = self.maximumNumberOfLines * self.messageLabel.font.lineHeight; + CGFloat maxHeight = ceilf(self.maximumNumberOfLines * self.messageLabel.font.lineHeight); #ifdef __IPHONE_7_0 - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - paragraphStyle.lineBreakMode = self.messageLabel.lineBreakMode; - - NSDictionary *attributes = @{NSFontAttributeName:self.messageLabel.font, - NSParagraphStyleAttributeName: paragraphStyle.copy}; - + NSDictionary *attributes = @{ + NSFontAttributeName:self.messageLabel.font, + }; // NSString class method: boundingRectWithSize:options:attributes:context is // available only on ios7.0 sdk. CGRect rect = [self.messageLabel.text boundingRectWithSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, maxHeight) From 203c9df81c9198417ed0dbf1010124053549394e Mon Sep 17 00:00:00 2001 From: Bruno Scheele Date: Tue, 2 Jun 2015 00:26:31 +0200 Subject: [PATCH 05/14] Add possibility to add a footerView with the height of a button. --- SIAlertView/SIAlertView.h | 1 + SIAlertView/SIAlertView.m | 30 +++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/SIAlertView/SIAlertView.h b/SIAlertView/SIAlertView.h index 4a51e7e..06bc694 100644 --- a/SIAlertView/SIAlertView.h +++ b/SIAlertView/SIAlertView.h @@ -44,6 +44,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView); @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *message; +@property (nonatomic, strong) UIView *footerView; @property (nonatomic, assign) SIAlertViewTransitionStyle transitionStyle; // default is SIAlertViewTransitionStyleSlideFromBottom @property (nonatomic, assign) SIAlertViewBackgroundStyle backgroundStyle; // default is SIAlertViewBackgroundStyleGradient diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 24bb2a5..9878a3e 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -766,11 +766,15 @@ - (void)validateLayout rect.origin.y += CANCEL_BUTTON_PADDING_TOP; button.frame = rect; } - y += BUTTON_HEIGHT + GAP; } + y += BUTTON_HEIGHT + GAP; } } } + if (self.footerView) { + y += GAP; + self.footerView.frame = CGRectMake(CONTENT_PADDING_LEFT, y, self.containerView.bounds.size.width - CONTENT_PADDING_LEFT * 2, BUTTON_HEIGHT); + } } - (CGFloat)preferredHeight @@ -798,6 +802,9 @@ - (CGFloat)preferredHeight } } } + if (self.footerView) { + height += GAP + BUTTON_HEIGHT; + } height += CONTENT_PADDING_BOTTOM; return height; } @@ -839,17 +846,14 @@ - (CGFloat)heightForTitleLabel - (CGFloat)heightForMessageLabel { - CGFloat minHeight = MESSAGE_MIN_LINE_COUNT * self.messageLabel.font.lineHeight; + CGFloat minHeight = ceilf(MESSAGE_MIN_LINE_COUNT * self.messageLabel.font.lineHeight); if (self.messageLabel) { - CGFloat maxHeight = self.maximumNumberOfLines * self.messageLabel.font.lineHeight; + CGFloat maxHeight = ceilf(self.maximumNumberOfLines * self.messageLabel.font.lineHeight); #ifdef __IPHONE_7_0 - NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; - paragraphStyle.lineBreakMode = self.messageLabel.lineBreakMode; - - NSDictionary *attributes = @{NSFontAttributeName:self.messageLabel.font, - NSParagraphStyleAttributeName: paragraphStyle.copy}; - + NSDictionary *attributes = @{ + NSFontAttributeName:self.messageLabel.font, + }; // NSString class method: boundingRectWithSize:options:attributes:context is // available only on ios7.0 sdk. CGRect rect = [self.messageLabel.text boundingRectWithSize:CGSizeMake(CONTAINER_WIDTH - CONTENT_PADDING_LEFT * 2, maxHeight) @@ -878,6 +882,7 @@ - (void)setup [self updateTitleLabel]; [self updateMessageLabel]; [self setupButtons]; + [self setupFooterView]; [self invalidateLayout]; } @@ -965,6 +970,13 @@ - (void)setupButtons } } +- (void)setupFooterView +{ + if (self.footerView) { + [self.containerView addSubview:self.footerView]; + } +} + - (UIButton *)buttonForItemIndex:(NSUInteger)index { SIAlertItem *item = self.items[index]; From 5be73d78197345f5093f215e40199b7d8375e712 Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Wed, 9 Sep 2015 17:01:51 +0200 Subject: [PATCH 06/14] secured textfield --- SIAlertView/SIAlertView.h | 2 +- SIAlertView/SIAlertView.m | 7 +++++-- .../xcshareddata/SIAlertViewExample.xccheckout | 16 ++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/SIAlertView/SIAlertView.h b/SIAlertView/SIAlertView.h index a743f8a..8ea6856 100644 --- a/SIAlertView/SIAlertView.h +++ b/SIAlertView/SIAlertView.h @@ -78,7 +78,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView); - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message; - (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type handler:(SIAlertViewHandler)handler; --(void)addTextFieldWithPlaceHolder:(NSString *)placeholder andText:(NSString *)text; +-(void)addTextFieldWithPlaceHolder:(NSString *)placeholder andText:(NSString *)text secured:(BOOL)secured; - (void)show; - (void)dismissAnimated:(BOOL)animated; diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 4ee5f2f..26c3f3a 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -144,6 +144,8 @@ @interface SITextItem : NSObject @property (nonatomic, copy) NSString *placeholder; @property (nonatomic, copy) NSString *text; +@property (nonatomic, assign)BOOL secured; + @end @@ -373,11 +375,12 @@ - (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type ha } --(void)addTextFieldWithPlaceHolder:(NSString *)placeholder andText:(NSString *)text +-(void)addTextFieldWithPlaceHolder:(NSString *)placeholder andText:(NSString *)text secured:(BOOL)secured { SITextItem *item = [[SITextItem alloc] init]; item.placeholder = placeholder; item.text = text; + item.secured = secured; [self.textFieldsItems addObject:item]; } @@ -1033,7 +1036,7 @@ - (UITextField *)textFieldForItemIndex:(NSUInteger)index textField.placeholder = item.placeholder; textField.text = item.text; - + textField.secureTextEntry = item.secured; textField.borderStyle=UITextBorderStyleRoundedRect; textField.autocorrectionType=UITextAutocorrectionTypeNo; textField.autocapitalizationType=UITextAutocapitalizationTypeNone; diff --git a/SIAlertViewExample/SIAlertViewExample.xcodeproj/project.xcworkspace/xcshareddata/SIAlertViewExample.xccheckout b/SIAlertViewExample/SIAlertViewExample.xcodeproj/project.xcworkspace/xcshareddata/SIAlertViewExample.xccheckout index 37fdd7b..b2c14a2 100644 --- a/SIAlertViewExample/SIAlertViewExample.xcodeproj/project.xcworkspace/xcshareddata/SIAlertViewExample.xccheckout +++ b/SIAlertViewExample/SIAlertViewExample.xcodeproj/project.xcworkspace/xcshareddata/SIAlertViewExample.xccheckout @@ -10,29 +10,29 @@ SIAlertViewExample IDESourceControlProjectOriginsDictionary - 1EE19127-7F15-4095-A45D-7D481FB08953 - https://github.com/Sumi-Interactive/SIAlertView.git + E2E339EC05FF99AF5ECAE62EDBC78398DA1111C6 + https://github.com/angu/SIAlertView IDESourceControlProjectPath - SIAlertViewExample/SIAlertViewExample.xcodeproj/project.xcworkspace + SIAlertViewExample/SIAlertViewExample.xcodeproj IDESourceControlProjectRelativeInstallPathDictionary - 1EE19127-7F15-4095-A45D-7D481FB08953 + E2E339EC05FF99AF5ECAE62EDBC78398DA1111C6 ../../.. IDESourceControlProjectURL - https://github.com/Sumi-Interactive/SIAlertView.git + https://github.com/angu/SIAlertView IDESourceControlProjectVersion - 110 + 111 IDESourceControlProjectWCCIdentifier - 1EE19127-7F15-4095-A45D-7D481FB08953 + E2E339EC05FF99AF5ECAE62EDBC78398DA1111C6 IDESourceControlProjectWCConfigurations IDESourceControlRepositoryExtensionIdentifierKey public.vcs.git IDESourceControlWCCIdentifierKey - 1EE19127-7F15-4095-A45D-7D481FB08953 + E2E339EC05FF99AF5ECAE62EDBC78398DA1111C6 IDESourceControlWCCName SIAlertView From 06ed6d4063fbd10a693c5a93c520943c35f3c07b Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Wed, 9 Sep 2015 17:18:29 +0200 Subject: [PATCH 07/14] textfield delegate --- SIAlertView/SIAlertView.m | 43 ++++++++++++++++++- .../SIAlertViewExample/ViewController.m | 1 + 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 26c3f3a..dcd5813 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -37,7 +37,7 @@ static SIAlertBackgroundWindow *__si_alert_background_window; static SIAlertView *__si_alert_current_view; -@interface SIAlertView () +@interface SIAlertView () @property (nonatomic, strong) NSMutableArray *items; @property (nonatomic, strong) NSMutableArray *textFieldsItems; @property (nonatomic, weak) UIWindow *oldKeyWindow; @@ -91,6 +91,8 @@ - (id)initWithFrame:(CGRect)frame andStyle:(SIAlertViewBackgroundStyle)style self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.opaque = NO; self.windowLevel = UIWindowLevelSIAlertBackground; + + } return self; } @@ -174,6 +176,7 @@ - (void)viewDidLoad { [super viewDidLoad]; [self.alertView setup]; + } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration @@ -277,6 +280,8 @@ - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message _enabledParallaxEffect = YES; self.items = [[NSMutableArray alloc] init]; self.textFieldsItems = [[NSMutableArray alloc] init]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidShow:) name:UIKeyboardDidShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardDidHideNotification object:nil]; } return self; } @@ -1034,7 +1039,7 @@ - (UITextField *)textFieldForItemIndex:(NSUInteger)index UITextField * textField = [[UITextField alloc] init]; textField.backgroundColor = [UIColor whiteColor]; textField.placeholder = item.placeholder; - + textField.delegate = self; textField.text = item.text; textField.secureTextEntry = item.secured; textField.borderStyle=UITextBorderStyleRoundedRect; @@ -1309,4 +1314,38 @@ - (void)removeParallaxEffect } #endif + + +#pragma mark UITextFieldDelegate +-(void)textFieldDidBeginEditing:(UITextField *)textField +{ + +} + +-(BOOL)textFieldShouldReturn:(UITextField *)textField +{ + [textField resignFirstResponder]; + return YES; +} + + +#pragma mark Keyboard notification handler +- (void)keyBoardDidShow:(NSNotification *)notification +{ + + NSDictionary* keyboardInfo = [notification userInfo]; + NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey]; + CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue]; + self.center = CGPointMake(self.center.x, self.center.y-keyboardFrameBeginRect.size.height/2); + +} +- (void)keyBoardDidHide:(NSNotification *)notification +{ + NSDictionary* keyboardInfo = [notification userInfo]; + NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey]; + CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue]; + self.center = CGPointMake(self.center.x, self.center.y+keyboardFrameBeginRect.size.height/2); + +} + @end diff --git a/SIAlertViewExample/SIAlertViewExample/ViewController.m b/SIAlertViewExample/SIAlertViewExample/ViewController.m index ec2687e..6bcac34 100644 --- a/SIAlertViewExample/SIAlertViewExample/ViewController.m +++ b/SIAlertViewExample/SIAlertViewExample/ViewController.m @@ -120,6 +120,7 @@ - (IBAction)alert2:(id)sender [self alert3:nil]; [self alert3:nil]; }]; + [alertView addTextFieldWithPlaceHolder:@"CODE" andText:@"CODE" secured:YES]; alertView.titleColor = [UIColor blueColor]; alertView.cornerRadius = 10; alertView.buttonFont = [UIFont boldSystemFontOfSize:15]; From 69881a04d6a1f41fab157d4a916cab781fec6a75 Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Thu, 10 Sep 2015 08:46:43 +0200 Subject: [PATCH 08/14] Modified notifications in 'will' --- SIAlertView/SIAlertView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index dcd5813..a7c1e41 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -280,8 +280,8 @@ - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message _enabledParallaxEffect = YES; self.items = [[NSMutableArray alloc] init]; self.textFieldsItems = [[NSMutableArray alloc] init]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidShow:) name:UIKeyboardDidShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardDidHideNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidShow:) name:UIKeyboardWillShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardWillHideNotification object:nil]; } return self; } From 32fc89efe6d6b6eea05769d3d879f0c90e61e37a Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Fri, 25 Sep 2015 16:44:26 +0200 Subject: [PATCH 09/14] removing observer --- SIAlertView/SIAlertView.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index a7c1e41..3a61a61 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -286,6 +286,14 @@ - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message return self; } +-(void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; + +} + + #pragma mark - Class methods + (NSMutableArray *)sharedQueue From a89f8be70a982c82f136bf65f446fcbb04122f9e Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Fri, 25 Sep 2015 17:09:36 +0200 Subject: [PATCH 10/14] keyboard fix --- SIAlertView/SIAlertView.m | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 3a61a61..b343c4a 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -51,6 +51,7 @@ @interface SIAlertView () @property (nonatomic, strong) UILabel *messageLabel; @property (nonatomic, strong) UIView *containerView; @property (nonatomic, strong) NSMutableArray *buttons; +@property (nonatomic, assign) CGPoint originalCenter; @property (nonatomic, assign, getter = isLayoutDirty) BOOL layoutDirty; @@ -471,6 +472,8 @@ - (void)show if (index < [SIAlertView sharedQueue].count - 1) { [self dismissAnimated:YES cleanup:NO]; // dismiss to show next alert view } + + self.originalCenter = self.center; }]; } @@ -1330,12 +1333,20 @@ -(void)textFieldDidBeginEditing:(UITextField *)textField } +-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ + return YES; +} + -(BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } +-(void)textFieldDidEndEditing:(UITextField *)textField +{ + [textField resignFirstResponder]; +} #pragma mark Keyboard notification handler - (void)keyBoardDidShow:(NSNotification *)notification @@ -1344,7 +1355,7 @@ - (void)keyBoardDidShow:(NSNotification *)notification NSDictionary* keyboardInfo = [notification userInfo]; NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey]; CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue]; - self.center = CGPointMake(self.center.x, self.center.y-keyboardFrameBeginRect.size.height/2); + self.center = CGPointMake(self.center.x, self.originalCenter.y-(keyboardFrameBeginRect.size.height/2)); } - (void)keyBoardDidHide:(NSNotification *)notification @@ -1352,7 +1363,7 @@ - (void)keyBoardDidHide:(NSNotification *)notification NSDictionary* keyboardInfo = [notification userInfo]; NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey]; CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue]; - self.center = CGPointMake(self.center.x, self.center.y+keyboardFrameBeginRect.size.height/2); + self.center = CGPointMake(self.center.x, self.originalCenter.y); } From 85444ed0ef6861c839660b965fb502e1f44e5604 Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Thu, 22 Oct 2015 11:01:55 +0200 Subject: [PATCH 11/14] iOS 9 fix --- SIAlertView/SIAlertView.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index b343c4a..10990c6 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -327,6 +327,8 @@ + (void)setAnimating:(BOOL)animating + (void)showBackground { + __si_alert_background_window.rootViewController = [UIViewController new]; + if (!__si_alert_background_window) { CGRect frame = [[UIScreen mainScreen] bounds]; From 92bb4e421dca2ef0197be1e3d3441a5d1f14ac7f Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Thu, 22 Oct 2015 12:05:07 +0200 Subject: [PATCH 12/14] fix --- SIAlertView/SIAlertView.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 10990c6..cd997c7 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -327,8 +327,6 @@ + (void)setAnimating:(BOOL)animating + (void)showBackground { - __si_alert_background_window.rootViewController = [UIViewController new]; - if (!__si_alert_background_window) { CGRect frame = [[UIScreen mainScreen] bounds]; @@ -339,6 +337,9 @@ + (void)showBackground __si_alert_background_window = [[SIAlertBackgroundWindow alloc] initWithFrame:frame andStyle:[SIAlertView currentAlertView].backgroundStyle]; + + __si_alert_background_window.rootViewController = [UIViewController new]; + [__si_alert_background_window makeKeyAndVisible]; __si_alert_background_window.alpha = 0; [UIView animateWithDuration:0.3 From 39ca912e36e203c3b7ce18b422fc4d5d9cce0f2f Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Wed, 19 Oct 2016 15:06:58 +0200 Subject: [PATCH 13/14] removed converting of screen frame of fixed coordinate --- SIAlertView/SIAlertView.m | 3 ++- .../SIAlertViewExample/SIAlertViewExample-Info.plist | 1 + SIAlertViewExample/SIAlertViewExample/ViewController.m | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index cd997c7..38172a6 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -332,7 +332,8 @@ + (void)showBackground CGRect frame = [[UIScreen mainScreen] bounds]; if([[UIScreen mainScreen] respondsToSelector:@selector(fixedCoordinateSpace)]) { - frame = [[[UIScreen mainScreen] fixedCoordinateSpace] convertRect:frame fromCoordinateSpace:[[UIScreen mainScreen] coordinateSpace]]; + //Why would we want to rotate the coordinates? +// frame = [[[UIScreen mainScreen] fixedCoordinateSpace] convertRect:frame fromCoordinateSpace:[[UIScreen mainScreen] coordinateSpace]]; } __si_alert_background_window = [[SIAlertBackgroundWindow alloc] initWithFrame:frame diff --git a/SIAlertViewExample/SIAlertViewExample/SIAlertViewExample-Info.plist b/SIAlertViewExample/SIAlertViewExample/SIAlertViewExample-Info.plist index 42dcd6e..23bb375 100644 --- a/SIAlertViewExample/SIAlertViewExample/SIAlertViewExample-Info.plist +++ b/SIAlertViewExample/SIAlertViewExample/SIAlertViewExample-Info.plist @@ -54,6 +54,7 @@ UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UIInterfaceOrientationPortraitUpsideDown UISupportedInterfaceOrientations~ipad diff --git a/SIAlertViewExample/SIAlertViewExample/ViewController.m b/SIAlertViewExample/SIAlertViewExample/ViewController.m index 6bcac34..cf1cc7f 100644 --- a/SIAlertViewExample/SIAlertViewExample/ViewController.m +++ b/SIAlertViewExample/SIAlertViewExample/ViewController.m @@ -10,7 +10,7 @@ #import "SIAlertView.h" #define TEST_UIAPPEARANCE 1 -#define TEST_AUTO_ROTATE 0 +#define TEST_AUTO_ROTATE 1 @interface ViewController () From db2cea5281ed9f031fe621390ae0c1c42212ed25 Mon Sep 17 00:00:00 2001 From: Andrea Tullis Date: Mon, 21 Nov 2016 22:55:04 +0100 Subject: [PATCH 14/14] fix for race condition on show and dismiss of first responder. --- SIAlertView/SIAlertView.m | 9 ++- .../SIAlertViewExample/ViewController.m | 36 ++++++------ .../en.lproj/MainStoryboard_iPhone.storyboard | 55 ++++++++++--------- 3 files changed, 53 insertions(+), 47 deletions(-) diff --git a/SIAlertView/SIAlertView.m b/SIAlertView/SIAlertView.m index 38172a6..30dee23 100644 --- a/SIAlertView/SIAlertView.m +++ b/SIAlertView/SIAlertView.m @@ -281,8 +281,7 @@ - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message _enabledParallaxEffect = YES; self.items = [[NSMutableArray alloc] init]; self.textFieldsItems = [[NSMutableArray alloc] init]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidShow:) name:UIKeyboardWillShowNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardWillHideNotification object:nil]; + } return self; } @@ -407,6 +406,7 @@ -(void)addTextFieldWithPlaceHolder:(NSString *)placeholder andText:(NSString *)t - (void)show { + if (self.isVisible) { return; } @@ -478,6 +478,8 @@ - (void)show } self.originalCenter = self.center; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidShow:) name:UIKeyboardWillShowNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardDidHide:) name:UIKeyboardWillHideNotification object:nil]; }]; } @@ -1355,7 +1357,7 @@ -(void)textFieldDidEndEditing:(UITextField *)textField #pragma mark Keyboard notification handler - (void)keyBoardDidShow:(NSNotification *)notification { - + NSDictionary* keyboardInfo = [notification userInfo]; NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey]; CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue]; @@ -1364,6 +1366,7 @@ - (void)keyBoardDidShow:(NSNotification *)notification } - (void)keyBoardDidHide:(NSNotification *)notification { + NSDictionary* keyboardInfo = [notification userInfo]; NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey]; CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue]; diff --git a/SIAlertViewExample/SIAlertViewExample/ViewController.m b/SIAlertViewExample/SIAlertViewExample/ViewController.m index cf1cc7f..e49b97c 100644 --- a/SIAlertViewExample/SIAlertViewExample/ViewController.m +++ b/SIAlertViewExample/SIAlertViewExample/ViewController.m @@ -21,24 +21,24 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; -#if TEST_UIAPPEARANCE - [[SIAlertView appearance] setMessageFont:[UIFont systemFontOfSize:13]]; - [[SIAlertView appearance] setTitleColor:[UIColor greenColor]]; - [[SIAlertView appearance] setMessageColor:[UIColor purpleColor]]; - [[SIAlertView appearance] setCornerRadius:12]; - [[SIAlertView appearance] setShadowRadius:20]; - [[SIAlertView appearance] setViewBackgroundColor:[UIColor colorWithRed:0.891 green:0.936 blue:0.978 alpha:1.000]]; - [[SIAlertView appearance] setButtonColor:[UIColor greenColor]]; - [[SIAlertView appearance] setCancelButtonColor:[UIColor redColor]]; - [[SIAlertView appearance] setDestructiveButtonColor:[UIColor blueColor]]; - - [[SIAlertView appearance] setDefaultButtonImage:[[UIImage imageNamed:@"button-default"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateNormal]; - [[SIAlertView appearance] setDefaultButtonImage:[[UIImage imageNamed:@"button-default-d"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateHighlighted]; - [[SIAlertView appearance] setCancelButtonImage:[[UIImage imageNamed:@"button-cancel"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateNormal]; - [[SIAlertView appearance] setCancelButtonImage:[[UIImage imageNamed:@"button-cancel-d"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateHighlighted]; - [[SIAlertView appearance] setDestructiveButtonImage:[[UIImage imageNamed:@"button-destructive"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateNormal]; - [[SIAlertView appearance] setDestructiveButtonImage:[[UIImage imageNamed:@"button-destructive-d"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateHighlighted]; -#endif +//#if TEST_UIAPPEARANCE +// [[SIAlertView appearance] setMessageFont:[UIFont systemFontOfSize:13]]; +// [[SIAlertView appearance] setTitleColor:[UIColor greenColor]]; +// [[SIAlertView appearance] setMessageColor:[UIColor purpleColor]]; +// [[SIAlertView appearance] setCornerRadius:12]; +// [[SIAlertView appearance] setShadowRadius:20]; +// [[SIAlertView appearance] setViewBackgroundColor:[UIColor colorWithRed:0.891 green:0.936 blue:0.978 alpha:1.000]]; +// [[SIAlertView appearance] setButtonColor:[UIColor greenColor]]; +// [[SIAlertView appearance] setCancelButtonColor:[UIColor redColor]]; +// [[SIAlertView appearance] setDestructiveButtonColor:[UIColor blueColor]]; +// +// [[SIAlertView appearance] setDefaultButtonImage:[[UIImage imageNamed:@"button-default"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateNormal]; +// [[SIAlertView appearance] setDefaultButtonImage:[[UIImage imageNamed:@"button-default-d"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateHighlighted]; +// [[SIAlertView appearance] setCancelButtonImage:[[UIImage imageNamed:@"button-cancel"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateNormal]; +// [[SIAlertView appearance] setCancelButtonImage:[[UIImage imageNamed:@"button-cancel-d"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateHighlighted]; +// [[SIAlertView appearance] setDestructiveButtonImage:[[UIImage imageNamed:@"button-destructive"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateNormal]; +// [[SIAlertView appearance] setDestructiveButtonImage:[[UIImage imageNamed:@"button-destructive-d"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,5,14,6)] forState:UIControlStateHighlighted]; +//#endif } #pragma mark - Actions diff --git a/SIAlertViewExample/SIAlertViewExample/en.lproj/MainStoryboard_iPhone.storyboard b/SIAlertViewExample/SIAlertViewExample/en.lproj/MainStoryboard_iPhone.storyboard index b3dbde3..0cd64bf 100644 --- a/SIAlertViewExample/SIAlertViewExample/en.lproj/MainStoryboard_iPhone.storyboard +++ b/SIAlertViewExample/SIAlertViewExample/en.lproj/MainStoryboard_iPhone.storyboard @@ -1,9 +1,9 @@ - + - - - + + + @@ -11,88 +11,91 @@ - + - + + + + + + + + - + - + - + - \ No newline at end of file +