From 6e01181efb648f45ce1553435def8f78f01c4446 Mon Sep 17 00:00:00 2001 From: Ashik Ahmad Date: Sun, 30 Jun 2013 20:13:25 +0600 Subject: [PATCH 1/3] added option to show closeButton left-top(default)/right-top --- KGModal.h | 5 +++++ KGModal.m | 5 +++++ readme.md | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/KGModal.h b/KGModal.h index 3edcfca..3353e16 100644 --- a/KGModal.h +++ b/KGModal.h @@ -27,6 +27,11 @@ typedef NS_ENUM(NSUInteger, KGModalBackgroundDisplayStyle){ // Defaults to YES @property (nonatomic) BOOL showCloseButton; +// Determines if position close button to right or left +// Defaults to NO (means left) +// This value only works when showCloseButton is YES +@property (nonatomic) BOOL closeButtonToRight; + // The background color of the modal window // Defaults black with 0.5 opacity @property (strong, nonatomic) UIColor *modalBackgroundColor; diff --git a/KGModal.m b/KGModal.m index f4d8067..cefb945 100644 --- a/KGModal.m +++ b/KGModal.m @@ -109,6 +109,11 @@ - (void)showWithContentView:(UIView *)contentView andAnimated:(BOOL)animated { self.containerView = containerView; KGModalCloseButton *closeButton = [[KGModalCloseButton alloc] init]; + if (self.closeButtonToRight) { + CGRect closeFrame = closeButton.frame; + closeFrame.origin.x = containerView.frame.size.width-padding-closeFrame.size.width/2; + closeButton.frame = closeFrame; + } [closeButton addTarget:self action:@selector(closeAction:) forControlEvents:UIControlEventTouchUpInside]; [closeButton setHidden:!self.showCloseButton]; [containerView addSubview:closeButton]; diff --git a/readme.md b/readme.md index e723404..ff88df8 100644 --- a/readme.md +++ b/readme.md @@ -23,6 +23,11 @@ There are a couple other options but it's purposely designed to be simple and ea // Defaults to YES @property (nonatomic) BOOL showCloseButton; +// Determines if position close button to right or left +// Defaults to NO (means left) +// This value only works when showCloseButton is YES +@property (nonatomic) BOOL closeButtonToRight; + // The background color of the modal window // Defaults black with 0.5 opacity @property (strong, nonatomic) UIColor *modalBackgroundColor; From d2538009ffba87621f797a4973e1a4e64684bc22 Mon Sep 17 00:00:00 2001 From: Ashik Ahmad Date: Wed, 11 Dec 2013 22:53:21 +0600 Subject: [PATCH 2/3] Added enum for closeButton types (none/left/right) --- ExampleApp/KGAppDelegate.m | 31 +++++++++++++++++-- .../KGModalExample.xcodeproj/project.pbxproj | 3 +- KGModal.h | 17 +++++----- KGModal.m | 31 ++++++++++++------- 4 files changed, 60 insertions(+), 22 deletions(-) diff --git a/ExampleApp/KGAppDelegate.m b/ExampleApp/KGAppDelegate.m index 50ada9e..4ab54dd 100644 --- a/ExampleApp/KGAppDelegate.m +++ b/ExampleApp/KGAppDelegate.m @@ -28,12 +28,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [showButton addTarget:self action:@selector(showAction:) forControlEvents:UIControlEventTouchUpInside]; [self.window.rootViewController.view addSubview:showButton]; + [KGModal sharedInstance].closeButtonType = KGModalCloseButtonTypeRight; + [self.window makeKeyAndVisible]; return YES; } - (void)showAction:(id)sender{ - UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 200)]; + UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 250)]; CGRect welcomeLabelRect = contentView.bounds; welcomeLabelRect.origin.y = 20; @@ -51,7 +53,7 @@ - (void)showAction:(id)sender{ CGRect infoLabelRect = CGRectInset(contentView.bounds, 5, 5); infoLabelRect.origin.y = CGRectGetMaxY(welcomeLabelRect)+5; - infoLabelRect.size.height -= CGRectGetMinY(infoLabelRect); + infoLabelRect.size.height -= CGRectGetMinY(infoLabelRect) + 50; UILabel *infoLabel = [[UILabel alloc] initWithFrame:infoLabelRect]; infoLabel.text = @"KGModal is an easy drop in control that allows you to display any view " "in a modal popup. The modal will automatically scale to fit the content view " @@ -63,8 +65,33 @@ - (void)showAction:(id)sender{ infoLabel.shadowColor = [UIColor blackColor]; infoLabel.shadowOffset = CGSizeMake(0, 1); [contentView addSubview:infoLabel]; + + CGFloat btnY = CGRectGetMaxY(infoLabelRect)+5; + CGFloat btnH = CGRectGetMaxY(contentView.frame)-5 - btnY; + UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + btn.frame = CGRectMake(infoLabelRect.origin.x, btnY, infoLabelRect.size.width, btnH); + [btn setTitle:@"Close Button Right" forState:UIControlStateNormal]; + [btn addTarget:self action:@selector(changeCloseButtonType:) forControlEvents:UIControlEventTouchUpInside]; + [contentView addSubview:btn]; [[KGModal sharedInstance] showWithContentView:contentView andAnimated:YES]; } +-(void) changeCloseButtonType:(id) sender { + UIButton *btn = (UIButton *) sender; + KGModal*modal = [KGModal sharedInstance]; + KGModalCloseButtonType type = modal.closeButtonType; + + if (KGModalCloseButtonTypeLeft == type) { + modal.closeButtonType = KGModalCloseButtonTypeRight; + [btn setTitle:@"Close Button Right" forState:UIControlStateNormal]; + } else if(KGModalCloseButtonTypeRight == type){ + modal.closeButtonType = KGModalCloseButtonTypeNone; + [btn setTitle:@"Close Button None" forState:UIControlStateNormal]; + } else { + modal.closeButtonType = KGModalCloseButtonTypeLeft; + [btn setTitle:@"Close Button Left" forState:UIControlStateNormal]; + } +} + @end diff --git a/ExampleApp/KGModalExample.xcodeproj/project.pbxproj b/ExampleApp/KGModalExample.xcodeproj/project.pbxproj index 399b3ca..5a5faa0 100644 --- a/ExampleApp/KGModalExample.xcodeproj/project.pbxproj +++ b/ExampleApp/KGModalExample.xcodeproj/project.pbxproj @@ -128,7 +128,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = KG; - LastUpgradeCheck = 0450; + LastUpgradeCheck = 0500; ORGANIZATIONNAME = "David Keegan"; }; buildConfigurationList = 73C8D4D4161F70CA007F378A /* Build configuration list for PBXProject "KGModalExample" */; @@ -198,6 +198,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 6.0; + ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/KGModal.h b/KGModal.h index 3353e16..5af3a5c 100644 --- a/KGModal.h +++ b/KGModal.h @@ -13,6 +13,12 @@ typedef NS_ENUM(NSUInteger, KGModalBackgroundDisplayStyle){ KGModalBackgroundDisplayStyleSolid }; +typedef NS_ENUM(NSUInteger, KGModalCloseButtonType) { + KGModalCloseButtonTypeNone = 0, + KGModalCloseButtonTypeLeft, + KGModalCloseButtonTypeRight +}; + @interface KGModal : NSObject // Determines if the modal should dismiss if the user taps outside of the modal view @@ -23,14 +29,9 @@ typedef NS_ENUM(NSUInteger, KGModalBackgroundDisplayStyle){ // Defaults to YES @property (nonatomic) BOOL animateWhenDismissed; -// Determins if the close button is shown -// Defaults to YES -@property (nonatomic) BOOL showCloseButton; - -// Determines if position close button to right or left -// Defaults to NO (means left) -// This value only works when showCloseButton is YES -@property (nonatomic) BOOL closeButtonToRight; +// Determins close button type (None/Left/Right) +// Defaults to Left +@property (nonatomic) KGModalCloseButtonType closeButtonType; // The background color of the modal window // Defaults black with 0.5 opacity diff --git a/KGModal.m b/KGModal.m index cefb945..3528b5c 100644 --- a/KGModal.m +++ b/KGModal.m @@ -12,6 +12,8 @@ CGFloat const kFadeInAnimationDuration = 0.3; CGFloat const kTransformPart1AnimationDuration = 0.2; CGFloat const kTransformPart2AnimationDuration = 0.1; +CGFloat const kDefaultCloseButtonPadding = 17.0; + NSString *const KGModalGradientViewTapped = @"KGModalGradientViewTapped"; @interface KGModalGradientView : UIView @@ -58,16 +60,26 @@ - (instancetype)init{ self.shouldRotate = YES; self.tapOutsideToDismiss = YES; self.animateWhenDismissed = YES; - self.showCloseButton = YES; + self.closeButtonType = KGModalCloseButtonTypeLeft; self.modalBackgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; return self; } -- (void)setShowCloseButton:(BOOL)showCloseButton{ - if(_showCloseButton != showCloseButton){ - _showCloseButton = showCloseButton; - [self.closeButton setHidden:!self.showCloseButton]; +-(void)setCloseButtonType:(KGModalCloseButtonType)closeButtonType { + _closeButtonType = closeButtonType; + if (closeButtonType == KGModalCloseButtonTypeNone) { + [self.closeButton setHidden:YES]; + } else { + [self.closeButton setHidden:NO]; + + CGRect closeFrame = self.closeButton.frame; + if (closeButtonType == KGModalCloseButtonTypeRight) { + closeFrame.origin.x = self.containerView.frame.size.width-kDefaultCloseButtonPadding-closeFrame.size.width/2; + } else { + closeFrame.origin.x = 0; + } + self.closeButton.frame = closeFrame; } } @@ -109,16 +121,13 @@ - (void)showWithContentView:(UIView *)contentView andAnimated:(BOOL)animated { self.containerView = containerView; KGModalCloseButton *closeButton = [[KGModalCloseButton alloc] init]; - if (self.closeButtonToRight) { - CGRect closeFrame = closeButton.frame; - closeFrame.origin.x = containerView.frame.size.width-padding-closeFrame.size.width/2; - closeButton.frame = closeFrame; - } [closeButton addTarget:self action:@selector(closeAction:) forControlEvents:UIControlEventTouchUpInside]; - [closeButton setHidden:!self.showCloseButton]; [containerView addSubview:closeButton]; self.closeButton = closeButton; + // Force adjust visibility and placing + [self setCloseButtonType:self.closeButtonType]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tapCloseAction:) name:KGModalGradientViewTapped object:nil]; From 6eef3b54b74ccb950ff35210dbce624fce8a0d27 Mon Sep 17 00:00:00 2001 From: Ashik Ahmad Date: Wed, 11 Dec 2013 23:14:09 +0600 Subject: [PATCH 3/3] updated readme --- readme.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index ff88df8..8b1793f 100644 --- a/readme.md +++ b/readme.md @@ -19,14 +19,9 @@ There are a couple other options but it's purposely designed to be simple and ea // Defaults to YES @property (nonatomic) BOOL animateWhenDismissed; -// Determins if the close button is shown -// Defaults to YES -@property (nonatomic) BOOL showCloseButton; - -// Determines if position close button to right or left -// Defaults to NO (means left) -// This value only works when showCloseButton is YES -@property (nonatomic) BOOL closeButtonToRight; +// Determins close button type (None/Left/Right) +// Defaults to Left +@property (nonatomic) KGModalCloseButtonType closeButtonType; // The background color of the modal window // Defaults black with 0.5 opacity