From 7777776d66ce972024bb384fd81081d9abc6cddb Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 14 Sep 2014 19:16:16 -0700 Subject: [PATCH 01/76] Initial implementation of SDCAlertAction --- SDCAlertView.xcodeproj/project.pbxproj | 29 ++++++++++++++- SDCAlertView/Source/SDCAlertAction.m | 46 ++++++++++++++++++++++++ SDCAlertView/Source/SDCAlertController.h | 45 +++++++++++++++++++++++ SDCAlertView/Source/SDCAlertController.m | 10 ++++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 SDCAlertView/Source/SDCAlertAction.m create mode 100644 SDCAlertView/Source/SDCAlertController.h create mode 100644 SDCAlertView/Source/SDCAlertController.m diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index 003ad25c..69487f0a 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -25,6 +25,8 @@ D263F1101829D1860001E4E0 /* SDCAlertViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D263F10F1829D1860001E4E0 /* SDCAlertViewController.m */; }; D263F1131829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = D263F1121829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m */; }; D263F1161829D31E0001E4E0 /* SDCAlertViewContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = D263F1151829D31E0001E4E0 /* SDCAlertViewContentView.m */; }; + D26506F219C67FC300BF34B9 /* SDCAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F119C67FC300BF34B9 /* SDCAlertController.m */; }; + D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F319C6812600BF34B9 /* SDCAlertAction.m */; }; D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */ = {isa = PBXBuildFile; fileRef = D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */; }; D2A520181840176300837A1A /* SDCAlertView.podspec in Resources */ = {isa = PBXBuildFile; fileRef = D2A520171840176300837A1A /* SDCAlertView.podspec */; }; D2BD0CC418FEB2C400520E33 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC318FEB2C400520E33 /* iPad.storyboard */; }; @@ -75,6 +77,9 @@ D263F1121829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertViewBackgroundView.m; sourceTree = ""; }; D263F1141829D31E0001E4E0 /* SDCAlertViewContentView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertViewContentView.h; sourceTree = ""; }; D263F1151829D31E0001E4E0 /* SDCAlertViewContentView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertViewContentView.m; sourceTree = ""; }; + D26506F019C67FC300BF34B9 /* SDCAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertController.h; sourceTree = ""; }; + D26506F119C67FC300BF34B9 /* SDCAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertController.m; sourceTree = ""; }; + D26506F319C6812600BF34B9 /* SDCAlertAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertAction.m; sourceTree = ""; }; D268093118F845420001B7E9 /* SDCAlertViewTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCAlertViewTransitioning.h; sourceTree = ""; }; D294876A18D631B700E3D967 /* SDCIntrinsicallySizedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCIntrinsicallySizedView.h; sourceTree = ""; }; D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCIntrinsicallySizedView.m; sourceTree = ""; }; @@ -130,6 +135,7 @@ 50B67E8F6417468B9958F089 /* Pods.xcconfig */, ); sourceTree = ""; + usesTabs = 1; }; D25B3CA517ECE7A6004B32A2 /* Products */ = { isa = PBXGroup; @@ -197,7 +203,7 @@ name = "Supporting Files"; sourceTree = ""; }; - D2F8347218EF2C09000BB281 /* Source */ = { + D26506EE19C61B7500BF34B9 /* 1.0 */ = { isa = PBXGroup; children = ( D2FA54921894AFB4006FAB5E /* SDCAlertViewCoordinator.h */, @@ -214,6 +220,25 @@ D263F1111829D2BD0001E4E0 /* SDCAlertViewBackgroundView.h */, D263F1121829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m */, ); + name = 1.0; + sourceTree = ""; + }; + D26506EF19C61B8000BF34B9 /* 2.0 */ = { + isa = PBXGroup; + children = ( + D26506F019C67FC300BF34B9 /* SDCAlertController.h */, + D26506F119C67FC300BF34B9 /* SDCAlertController.m */, + D26506F319C6812600BF34B9 /* SDCAlertAction.m */, + ); + name = 2.0; + sourceTree = ""; + }; + D2F8347218EF2C09000BB281 /* Source */ = { + isa = PBXGroup; + children = ( + D26506EE19C61B7500BF34B9 /* 1.0 */, + D26506EF19C61B8000BF34B9 /* 2.0 */, + ); path = Source; sourceTree = ""; }; @@ -391,12 +416,14 @@ D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */, D25B3CB417ECE7A6004B32A2 /* main.m in Sources */, D25B3CDE17ECF1C5004B32A2 /* SDCAlertView.m in Sources */, + D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */, D263F1131829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m in Sources */, D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */, D263F1101829D1860001E4E0 /* SDCAlertViewController.m in Sources */, D2FA54941894AFB5006FAB5E /* SDCAlertViewCoordinator.m in Sources */, D25B3CB817ECE7A6004B32A2 /* SDCAppDelegate.m in Sources */, D263F1161829D31E0001E4E0 /* SDCAlertViewContentView.m in Sources */, + D26506F219C67FC300BF34B9 /* SDCAlertController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/SDCAlertView/Source/SDCAlertAction.m b/SDCAlertView/Source/SDCAlertAction.m new file mode 100644 index 00000000..287c9919 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertAction.m @@ -0,0 +1,46 @@ +// +// SDCAlertAction.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/14/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertController.h" + +@interface SDCAlertAction () +@property (nonatomic, copy) void (^handler)(SDCAlertAction *); +@end + +@implementation SDCAlertAction + +#pragma mark - Initialization + ++ (instancetype)actionWithTitle:(NSString *)title style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *))handler { + SDCAlertAction *action = [[self alloc] initWithTitle:title style:style handler:handler]; + return action; +} + +- (instancetype)initWithTitle:(NSString *)title style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *))handler { + self = [self init]; + + if (self) { + _title = title; + _style = style; + _handler = handler; + } + + return self; +} + +#pragma mark - NSCopying + +- (id)copyWithZone:(NSZone *)zone { + NSString *title = [self.title copy]; + void (^handler)(SDCAlertAction *) = [self.handler copy]; + + id copy = [[[self class] alloc] initWithTitle:title style:self.style handler:handler]; + return copy; +} + +@end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h new file mode 100644 index 00000000..cfb065d6 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertController.h @@ -0,0 +1,45 @@ +// +// SDCAlertController.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/14/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertController.h" + +typedef NS_ENUM(NSInteger, SDCAlertActionStyle) { + SDCAlertActionStyleDefault = UIAlertActionStyleDefault, + SDCAlertActionStyleCancel = UIAlertActionStyleCancel, + SDCAlertActionStyleDestructive = UIAlertActionStyleDestructive +}; + +typedef NS_ENUM(NSInteger, SDCAlertControllerStyle) { + SDCAlertControllerStyleAlert = UIAlertControllerStyleAlert +}; + +@interface SDCAlertAction : NSObject + ++ (instancetype)actionWithTitle:(NSString *)title style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *action))handler; + +@property (nonatomic, readonly) NSString *title; +@property (nonatomic, readonly) SDCAlertActionStyle style; +@property (nonatomic, getter=isEnabled) BOOL enabled; + +@end + +@interface SDCAlertController : UIViewController + ++ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(SDCAlertControllerStyle)preferredStyle; + +- (void)addAction:(SDCAlertAction *)action; +@property (nonatomic, readonly) NSArray *actions; +- (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler; +@property (nonatomic, readonly) NSArray *textFields; + +@property (nonatomic, copy) NSString *title; +@property (nonatomic, copy) NSString *message; + +@property (nonatomic, readonly) SDCAlertControllerStyle preferredStyle; + +@end diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m new file mode 100644 index 00000000..7d0ef656 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertController.m @@ -0,0 +1,10 @@ +// +// SDCAlertController.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/14/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertController.h" + From 6832b109c169065bbedab58f6e68a07248401379 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 21 Sep 2014 01:27:25 -0700 Subject: [PATCH 02/76] Use UIPresentationController for alert presentation --- SDCAlertView.xcodeproj/project.pbxproj | 12 +++ SDCAlertView/SDCViewController.m | 34 +++++++-- SDCAlertView/Source/SDCAlertController.m | 63 ++++++++++++++++ .../Source/SDCAlertPresentationController.h | 13 ++++ .../Source/SDCAlertPresentationController.m | 53 +++++++++++++ SDCAlertView/Source/SDCAlertTransition.h | 17 +++++ SDCAlertView/Source/SDCAlertTransition.m | 75 +++++++++++++++++++ 7 files changed, 260 insertions(+), 7 deletions(-) create mode 100644 SDCAlertView/Source/SDCAlertPresentationController.h create mode 100644 SDCAlertView/Source/SDCAlertPresentationController.m create mode 100644 SDCAlertView/Source/SDCAlertTransition.h create mode 100644 SDCAlertView/Source/SDCAlertTransition.m diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index 69487f0a..67c3a104 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 4B64D41583994B9C9C59A4E3 /* libPods-SDCAlertViewTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CB28936541154BCF9C9B2F0C /* libPods-SDCAlertViewTests.a */; }; + D259FC1219CEB02100BA6B36 /* SDCAlertPresentationController.m in Sources */ = {isa = PBXBuildFile; fileRef = D259FC1119CEB02100BA6B36 /* SDCAlertPresentationController.m */; }; + D259FC1519CEB0EB00BA6B36 /* SDCAlertTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = D259FC1419CEB0EB00BA6B36 /* SDCAlertTransition.m */; }; D25B3CA817ECE7A6004B32A2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D25B3CA717ECE7A6004B32A2 /* Foundation.framework */; }; D25B3CAA17ECE7A6004B32A2 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D25B3CA917ECE7A6004B32A2 /* CoreGraphics.framework */; }; D25B3CAC17ECE7A6004B32A2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D25B3CAB17ECE7A6004B32A2 /* UIKit.framework */; }; @@ -51,6 +53,10 @@ /* Begin PBXFileReference section */ 50B67E8F6417468B9958F089 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; CB28936541154BCF9C9B2F0C /* libPods-SDCAlertViewTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-SDCAlertViewTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + D259FC1019CEB02100BA6B36 /* SDCAlertPresentationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertPresentationController.h; sourceTree = ""; }; + D259FC1119CEB02100BA6B36 /* SDCAlertPresentationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertPresentationController.m; sourceTree = ""; }; + D259FC1319CEB0EB00BA6B36 /* SDCAlertTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertTransition.h; sourceTree = ""; }; + D259FC1419CEB0EB00BA6B36 /* SDCAlertTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertTransition.m; sourceTree = ""; }; D25B3CA417ECE7A6004B32A2 /* SDCAlertView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SDCAlertView.app; sourceTree = BUILT_PRODUCTS_DIR; }; D25B3CA717ECE7A6004B32A2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; D25B3CA917ECE7A6004B32A2 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -226,6 +232,10 @@ D26506EF19C61B8000BF34B9 /* 2.0 */ = { isa = PBXGroup; children = ( + D259FC1019CEB02100BA6B36 /* SDCAlertPresentationController.h */, + D259FC1119CEB02100BA6B36 /* SDCAlertPresentationController.m */, + D259FC1319CEB0EB00BA6B36 /* SDCAlertTransition.h */, + D259FC1419CEB0EB00BA6B36 /* SDCAlertTransition.m */, D26506F019C67FC300BF34B9 /* SDCAlertController.h */, D26506F119C67FC300BF34B9 /* SDCAlertController.m */, D26506F319C6812600BF34B9 /* SDCAlertAction.m */, @@ -415,6 +425,8 @@ files = ( D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */, D25B3CB417ECE7A6004B32A2 /* main.m in Sources */, + D259FC1519CEB0EB00BA6B36 /* SDCAlertTransition.m in Sources */, + D259FC1219CEB02100BA6B36 /* SDCAlertPresentationController.m in Sources */, D25B3CDE17ECF1C5004B32A2 /* SDCAlertView.m in Sources */, D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */, D263F1131829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m in Sources */, diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index f2adc943..6d5600eb 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -13,20 +13,40 @@ #import "SDCAlertView.h" #import "UIView+SDCAutoLayout.h" -@interface SDCViewController () +#import "SDCAlertController.h" +#import "SDCAlertTransition.h" +@interface SDCViewController () +@property (nonatomic, strong) idtransitioningDelegate2; @end @implementation SDCViewController +- (void)presentNow { + UIAlertController *b = [UIAlertController alertControllerWithTitle:@"Title 2" message:@"Message 2" preferredStyle:UIAlertControllerStyleAlert]; + [b addAction:[UIAlertAction actionWithTitle:@"Button 2" style:UIAlertActionStyleDefault handler:nil]]; + + [self presentViewController:b animated:YES completion:nil]; +} + - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { - UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"Title" - message:@"This is a message" - delegate:self - cancelButtonTitle:@"Cancel" - otherButtonTitles:@"Button 1", @"Button 2", nil]; - [a show]; +// UIAlertController *a = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert]; +// [a addAction:[UIAlertAction actionWithTitle:@"Button" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { +// a; +// +// }]]; +// +// [self presentViewController:a animated:YES completion:^{ +// [self performSelector:@selector(presentNow) withObject:nil afterDelay:1]; +// }]; + + self.transitioningDelegate2 = [[SDCAlertTransitioningDelegate alloc] init]; + + SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; + ac.transitioningDelegate = self.transitioningDelegate2; + + [self presentViewController:ac animated:YES completion:nil]; } else if (indexPath.section == 1) { if (indexPath.row == 0) { diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 7d0ef656..9c5886a9 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -8,3 +8,66 @@ #import "SDCAlertController.h" +#import "SDCAlertTransition.h" + +@interface SDCAlertController () +@property (nonatomic, strong) NSMutableArray *mutableActions; +@property (nonatomic, strong) NSMutableArray *textFieldConfigurationHandlers; +@end + +@implementation SDCAlertController + +#pragma mark - Creation + ++ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(SDCAlertControllerStyle)preferredStyle { + SDCAlertController *alert = [[self alloc] initWithTitle:title message:message preferredStyle:preferredStyle]; + return alert; +} + +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(SDCAlertControllerStyle)preferredStyle { + self = [self init]; + + NSAssert(preferredStyle == SDCAlertControllerStyleAlert, @"Only SDCAlertControllerStyleAlert is supported by %@", NSStringFromClass([self class])); + + if (self) { + self.title = title; + _message = message; + + _mutableActions = [NSMutableArray array]; + _textFieldConfigurationHandlers = [NSMutableArray array]; + + self.modalPresentationStyle = UIModalPresentationCustom; + } + + return self; +} + +#pragma mark - Style + +- (SDCAlertControllerStyle)preferredStyle { + return SDCAlertControllerStyleAlert; +} + +#pragma mark - Alert Actions + +- (void)addAction:(SDCAlertAction *)action { + [self.mutableActions addObject:action]; +} + +- (NSArray *)actions { + return [self.mutableActions copy]; +} + +#pragma mark - Alert Text Fields + +- (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *))configurationHandler { + [self.textFieldConfigurationHandlers addObject:[configurationHandler copy]]; +} + +- (NSArray *)textFields { + return [NSArray array]; +} + + + +@end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertPresentationController.h b/SDCAlertView/Source/SDCAlertPresentationController.h new file mode 100644 index 00000000..e2a42587 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertPresentationController.h @@ -0,0 +1,13 @@ +// +// SDCAlertPresentationController.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +@interface SDCAlertPresentationController : UIPresentationController + +@end diff --git a/SDCAlertView/Source/SDCAlertPresentationController.m b/SDCAlertView/Source/SDCAlertPresentationController.m new file mode 100644 index 00000000..2a53d6e9 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertPresentationController.m @@ -0,0 +1,53 @@ +// +// SDCAlertPresentationController.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertPresentationController.h" + +@interface SDCAlertPresentationController () +@property (nonatomic, strong) UIView *dimmingView; +@end + +@implementation SDCAlertPresentationController + +- (instancetype)initWithPresentedViewController:(UIViewController *)presentedViewController presentingViewController:(UIViewController *)presentingViewController { + self = [super initWithPresentedViewController:presentedViewController presentingViewController:presentedViewController]; + + if (self) { + _dimmingView = [[UIView alloc] init]; + _dimmingView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4]; + } + + return self; +} + +- (void)presentationTransitionWillBegin { + [super presentationTransitionWillBegin]; + + self.dimmingView.alpha = 0; + [[self containerView] addSubview:self.dimmingView]; + + [self.presentedViewController.transitionCoordinator animateAlongsideTransition:^(id context) { + self.dimmingView.alpha = 1; + } completion:nil]; +} + +- (void)dismissalTransitionWillBegin { + [super dismissalTransitionWillBegin]; + + [self.presentedViewController.transitionCoordinator animateAlongsideTransition:^(id context) { + self.dimmingView.alpha = 0; + } completion:nil]; +} + +- (void)containerViewWillLayoutSubviews { + [super containerViewWillLayoutSubviews]; + + self.dimmingView.frame = self.containerView.frame; +} + +@end diff --git a/SDCAlertView/Source/SDCAlertTransition.h b/SDCAlertView/Source/SDCAlertTransition.h new file mode 100644 index 00000000..65caa7b0 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertTransition.h @@ -0,0 +1,17 @@ +// +// SDCAlertTransition.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +@interface SDCAlertAnimationController : NSObject +@property (nonatomic, getter=isPresentation) BOOL presentation; +@end + +@interface SDCAlertTransitioningDelegate : NSObject + +@end diff --git a/SDCAlertView/Source/SDCAlertTransition.m b/SDCAlertView/Source/SDCAlertTransition.m new file mode 100644 index 00000000..4e2eb209 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertTransition.m @@ -0,0 +1,75 @@ +// +// SDCAlertTransition.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertTransition.h" + +#import "SDCAlertPresentationController.h" + +@implementation SDCAlertTransitioningDelegate + +- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented + presentingViewController:(UIViewController *)presenting + sourceViewController:(UIViewController *)source { + return [[SDCAlertPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting]; +} + +- (SDCAlertAnimationController *)animationControllerForPresentation:(BOOL)presentation { + SDCAlertAnimationController *animationController = [[SDCAlertAnimationController alloc] init]; + animationController.presentation = presentation; + return animationController; +} + +- (id)animationControllerForPresentedController:(UIViewController *)presented + presentingController:(UIViewController *)presenting + sourceController:(UIViewController *)source { + return [self animationControllerForPresentation:YES]; +} + +- (id)animationControllerForDismissedController:(UIViewController *)dismissed { + return [self animationControllerForPresentation:NO]; +} + +@end + + +@implementation SDCAlertAnimationController + +- (NSTimeInterval)transitionDuration:(id)transitionContext { + return .25; +} + +- (void)animateTransition:(id)transitionContext { + UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; + UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; + + if (self.isPresentation) { + [[transitionContext containerView] addSubview:toViewController.view]; + } + + UIViewController *animatingViewController = self.isPresentation ? toViewController : fromViewController; + UIView *animatingView = animatingViewController.view; + + animatingView.frame = [transitionContext finalFrameForViewController:animatingViewController]; + + CGAffineTransform presentedTransform = CGAffineTransformIdentity; + CGAffineTransform dismissedTransform = CGAffineTransformMakeScale(0.0001, 0.0001); + + animatingView.transform = self.isPresentation ? dismissedTransform : presentedTransform; + + [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ + animatingView.transform = self.isPresentation ? presentedTransform : dismissedTransform; + } completion:^(BOOL finished) { + if (!self.isPresentation) { + [fromViewController.view removeFromSuperview]; + } + + [transitionContext completeTransition:finished]; + }]; +} + +@end \ No newline at end of file From 10d8548d8ce593af352613e07852db95294b0f54 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 21 Sep 2014 13:52:31 -0700 Subject: [PATCH 03/76] Retain transitioningDelegate to avoid crash --- SDCAlertView/SDCViewController.m | 13 ------------- SDCAlertView/Source/SDCAlertController.m | 2 ++ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 6d5600eb..657af03e 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -17,7 +17,6 @@ #import "SDCAlertTransition.h" @interface SDCViewController () -@property (nonatomic, strong) idtransitioningDelegate2; @end @implementation SDCViewController @@ -31,20 +30,8 @@ - (void)presentNow { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { -// UIAlertController *a = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert]; -// [a addAction:[UIAlertAction actionWithTitle:@"Button" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { -// a; -// -// }]]; -// -// [self presentViewController:a animated:YES completion:^{ -// [self performSelector:@selector(presentNow) withObject:nil afterDelay:1]; -// }]; - - self.transitioningDelegate2 = [[SDCAlertTransitioningDelegate alloc] init]; SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; - ac.transitioningDelegate = self.transitioningDelegate2; [self presentViewController:ac animated:YES completion:nil]; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 9c5886a9..72abc9e4 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -13,6 +13,7 @@ @interface SDCAlertController () @property (nonatomic, strong) NSMutableArray *mutableActions; @property (nonatomic, strong) NSMutableArray *textFieldConfigurationHandlers; +@property (nonatomic, strong) id transitioningDelegate; @end @implementation SDCAlertController @@ -37,6 +38,7 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref _textFieldConfigurationHandlers = [NSMutableArray array]; self.modalPresentationStyle = UIModalPresentationCustom; + self.transitioningDelegate = [[SDCAlertTransitioningDelegate alloc] init]; } return self; From a7467fd80a597d226d57f1541d3db3c5c6ed4085 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 21 Sep 2014 23:20:26 -0700 Subject: [PATCH 04/76] Initial implementation for SDCAlertScrollView --- SDCAlertView.xcodeproj/project.pbxproj | 18 +++++ SDCAlertView/SDCViewController.m | 7 +- SDCAlertView/Source/SDCAlertController.m | 15 ++++ SDCAlertView/Source/SDCAlertLabel.h | 13 ++++ SDCAlertView/Source/SDCAlertLabel.m | 30 ++++++++ SDCAlertView/Source/SDCAlertScrollView.h | 17 +++++ SDCAlertView/Source/SDCAlertScrollView.m | 95 ++++++++++++++++++++++++ SDCAlertView/Source/SDCAlertViewNew.h | 18 +++++ SDCAlertView/Source/SDCAlertViewNew.m | 44 +++++++++++ 9 files changed, 255 insertions(+), 2 deletions(-) create mode 100644 SDCAlertView/Source/SDCAlertLabel.h create mode 100644 SDCAlertView/Source/SDCAlertLabel.m create mode 100644 SDCAlertView/Source/SDCAlertScrollView.h create mode 100644 SDCAlertView/Source/SDCAlertScrollView.m create mode 100644 SDCAlertView/Source/SDCAlertViewNew.h create mode 100644 SDCAlertView/Source/SDCAlertViewNew.m diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index 67c3a104..0397009f 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -29,6 +29,9 @@ D263F1161829D31E0001E4E0 /* SDCAlertViewContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = D263F1151829D31E0001E4E0 /* SDCAlertViewContentView.m */; }; D26506F219C67FC300BF34B9 /* SDCAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F119C67FC300BF34B9 /* SDCAlertController.m */; }; D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F319C6812600BF34B9 /* SDCAlertAction.m */; }; + D2666A4019CFDE2800167157 /* SDCAlertViewNew.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A3F19CFDE2800167157 /* SDCAlertViewNew.m */; }; + D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */; }; + D2666A4619CFE0F900167157 /* SDCAlertLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4519CFE0F900167157 /* SDCAlertLabel.m */; }; D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */ = {isa = PBXBuildFile; fileRef = D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */; }; D2A520181840176300837A1A /* SDCAlertView.podspec in Resources */ = {isa = PBXBuildFile; fileRef = D2A520171840176300837A1A /* SDCAlertView.podspec */; }; D2BD0CC418FEB2C400520E33 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC318FEB2C400520E33 /* iPad.storyboard */; }; @@ -86,6 +89,12 @@ D26506F019C67FC300BF34B9 /* SDCAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertController.h; sourceTree = ""; }; D26506F119C67FC300BF34B9 /* SDCAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertController.m; sourceTree = ""; }; D26506F319C6812600BF34B9 /* SDCAlertAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertAction.m; sourceTree = ""; }; + D2666A3E19CFDE2800167157 /* SDCAlertViewNew.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertViewNew.h; sourceTree = ""; }; + D2666A3F19CFDE2800167157 /* SDCAlertViewNew.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertViewNew.m; sourceTree = ""; }; + D2666A4119CFDF6700167157 /* SDCAlertScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertScrollView.h; sourceTree = ""; }; + D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertScrollView.m; sourceTree = ""; }; + D2666A4419CFE0F900167157 /* SDCAlertLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertLabel.h; sourceTree = ""; }; + D2666A4519CFE0F900167157 /* SDCAlertLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertLabel.m; sourceTree = ""; }; D268093118F845420001B7E9 /* SDCAlertViewTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCAlertViewTransitioning.h; sourceTree = ""; }; D294876A18D631B700E3D967 /* SDCIntrinsicallySizedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCIntrinsicallySizedView.h; sourceTree = ""; }; D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCIntrinsicallySizedView.m; sourceTree = ""; }; @@ -232,6 +241,12 @@ D26506EF19C61B8000BF34B9 /* 2.0 */ = { isa = PBXGroup; children = ( + D2666A3E19CFDE2800167157 /* SDCAlertViewNew.h */, + D2666A3F19CFDE2800167157 /* SDCAlertViewNew.m */, + D2666A4119CFDF6700167157 /* SDCAlertScrollView.h */, + D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */, + D2666A4419CFE0F900167157 /* SDCAlertLabel.h */, + D2666A4519CFE0F900167157 /* SDCAlertLabel.m */, D259FC1019CEB02100BA6B36 /* SDCAlertPresentationController.h */, D259FC1119CEB02100BA6B36 /* SDCAlertPresentationController.m */, D259FC1319CEB0EB00BA6B36 /* SDCAlertTransition.h */, @@ -428,11 +443,14 @@ D259FC1519CEB0EB00BA6B36 /* SDCAlertTransition.m in Sources */, D259FC1219CEB02100BA6B36 /* SDCAlertPresentationController.m in Sources */, D25B3CDE17ECF1C5004B32A2 /* SDCAlertView.m in Sources */, + D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */, + D2666A4019CFDE2800167157 /* SDCAlertViewNew.m in Sources */, D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */, D263F1131829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m in Sources */, D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */, D263F1101829D1860001E4E0 /* SDCAlertViewController.m in Sources */, D2FA54941894AFB5006FAB5E /* SDCAlertViewCoordinator.m in Sources */, + D2666A4619CFE0F900167157 /* SDCAlertLabel.m in Sources */, D25B3CB817ECE7A6004B32A2 /* SDCAppDelegate.m in Sources */, D263F1161829D31E0001E4E0 /* SDCAlertViewContentView.m in Sources */, D26506F219C67FC300BF34B9 /* SDCAlertController.m in Sources */, diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 657af03e..0ba86bc2 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -25,16 +25,19 @@ - (void)presentNow { UIAlertController *b = [UIAlertController alertControllerWithTitle:@"Title 2" message:@"Message 2" preferredStyle:UIAlertControllerStyleAlert]; [b addAction:[UIAlertAction actionWithTitle:@"Button 2" style:UIAlertActionStyleDefault handler:nil]]; - [self presentViewController:b animated:YES completion:nil]; + [self presentViewController:b animated:YES completion:^{ + b.title = @""; + }]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; - [self presentViewController:ac animated:YES completion:nil]; + //[self presentNow]; + } else if (indexPath.section == 1) { if (indexPath.row == 0) { SDCAlertView *a = [[SDCAlertView alloc] initWithTitle:@"Title" diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 72abc9e4..d169ed56 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -9,6 +9,8 @@ #import "SDCAlertController.h" #import "SDCAlertTransition.h" +#import "SDCAlertViewNew.h" +#import "UIView+SDCAutoLayout.h" @interface SDCAlertController () @property (nonatomic, strong) NSMutableArray *mutableActions; @@ -44,6 +46,19 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref return self; } +#pragma mark - Alert View + +- (void)viewDidLoad { + [super viewDidLoad]; + + SDCAlertViewNew *alert = [[SDCAlertViewNew alloc] initWithTitle:self.title message:self.message]; + [alert sdc_pinSize:CGSizeMake(270, 120)]; + + [self.view addSubview:alert]; + [alert sdc_centerInSuperview]; + [alert layoutIfNeeded]; +} + #pragma mark - Style - (SDCAlertControllerStyle)preferredStyle { diff --git a/SDCAlertView/Source/SDCAlertLabel.h b/SDCAlertView/Source/SDCAlertLabel.h new file mode 100644 index 00000000..efa5de2b --- /dev/null +++ b/SDCAlertView/Source/SDCAlertLabel.h @@ -0,0 +1,13 @@ +// +// SDCAlertLabel.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +@interface SDCAlertLabel : UILabel + +@end diff --git a/SDCAlertView/Source/SDCAlertLabel.m b/SDCAlertView/Source/SDCAlertLabel.m new file mode 100644 index 00000000..f8487864 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertLabel.m @@ -0,0 +1,30 @@ +// +// SDCAlertLabel.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertLabel.h" + +@implementation SDCAlertLabel + +- (instancetype)init { + self = [super init]; + + if (self) { + [self setTranslatesAutoresizingMaskIntoConstraints:NO]; + self.textAlignment = NSTextAlignmentCenter; + self.numberOfLines = 0; + } + + return self; +} + +- (void)layoutSubviews { + self.preferredMaxLayoutWidth = CGRectGetWidth(self.bounds); + [super layoutSubviews]; +} + +@end diff --git a/SDCAlertView/Source/SDCAlertScrollView.h b/SDCAlertView/Source/SDCAlertScrollView.h new file mode 100644 index 00000000..53e513dc --- /dev/null +++ b/SDCAlertView/Source/SDCAlertScrollView.h @@ -0,0 +1,17 @@ +// +// SDCAlertScrollView.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +@import UIKit; + +@interface SDCAlertScrollView : UIScrollView + +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; + +- (void)prepareForDisplay; + +@end diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m new file mode 100644 index 00000000..18c55729 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -0,0 +1,95 @@ +// +// SDCAlertScrollView.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertScrollView.h" +#import "SDCAlertLabel.h" +#import "UIView+SDCAutoLayout.h" + +static UIEdgeInsets const SDCAlertScrollViewInsets = {19, 15, 18.5, 15}; +static CGFloat const SDCAlertScrollViewLabelSpacing = 4; + +@interface SDCAlertScrollView () +@property (nonatomic, strong) NSString *title; +@property (nonatomic, strong) SDCAlertLabel *titleLabel; +@property (nonatomic, strong) NSString *message; +@property (nonatomic, strong) SDCAlertLabel *messageLabel; +@end + +@implementation SDCAlertScrollView + +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { + self = [self init]; + + if (self) { + _titleLabel = [[SDCAlertLabel alloc] init]; + _messageLabel = [[SDCAlertLabel alloc] init]; + + self.title = title; + self.message = message; + + self.contentInset = SDCAlertScrollViewInsets; + self.scrollIndicatorInsets = SDCAlertScrollViewInsets; + + [self setTranslatesAutoresizingMaskIntoConstraints:NO]; + } + + return self; +} + +- (void)setTitle:(NSString *)title { + BOOL requiresViewHierarchyUpdate = (_title && !title) || (!_title && title); + + _title = title; + _titleLabel.text = title; + + if (requiresViewHierarchyUpdate && self.superview) { + [self updateViewHierarchy]; + } +} + +- (void)setMessage:(NSString *)message { + BOOL requiresViewHierarchyUpdate = (_message && !message) || (!_message && message); + + _message = message; + _messageLabel.text = message; + + if (requiresViewHierarchyUpdate && self.superview) { + [self updateViewHierarchy]; + } +} + +- (void)prepareForDisplay { + [self updateViewHierarchy]; +} + +- (void)updateViewHierarchy { + if (self.title.length > 0) { + [self addSubview:self.titleLabel]; + [self.titleLabel sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop]; + [self.titleLabel sdc_pinWidthToWidthOfView:self offset:-(SDCAlertScrollViewInsets.left + SDCAlertScrollViewInsets.right)]; + } else { + [self.titleLabel removeFromSuperview]; + } + + if (self.message.length > 0) { + [self addSubview:self.messageLabel]; + [self.messageLabel sdc_alignEdgesWithSuperview:UIRectEdgeLeft]; + [self.messageLabel sdc_pinWidthToWidthOfView:self offset:-(SDCAlertScrollViewInsets.left + SDCAlertScrollViewInsets.right)]; + + if (self.title.length > 0) { + [self.messageLabel sdc_pinVerticalSpacing:SDCAlertScrollViewLabelSpacing toView:self.titleLabel]; + } else { + [self.messageLabel sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeTop ofView:self inset:SDCAlertScrollViewLabelSpacing]; + } + } else { + [self.messageLabel removeFromSuperview]; + } +} + + +@end diff --git a/SDCAlertView/Source/SDCAlertViewNew.h b/SDCAlertView/Source/SDCAlertViewNew.h new file mode 100644 index 00000000..eb9401f8 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertViewNew.h @@ -0,0 +1,18 @@ +// +// SDCAlertViewNew.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +@interface SDCAlertViewNew : UIView + +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; + +@property (nonatomic, copy) NSString *title; +@property (nonatomic, copy) NSString *message; + +@end diff --git a/SDCAlertView/Source/SDCAlertViewNew.m b/SDCAlertView/Source/SDCAlertViewNew.m new file mode 100644 index 00000000..aa45f834 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertViewNew.m @@ -0,0 +1,44 @@ +// +// SDCAlertViewNew.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertViewNew.h" + +#import "SDCAlertScrollView.h" +#import "UIView+SDCAutoLayout.h" + + +@interface SDCAlertViewNew () +@property (nonatomic, strong) SDCAlertScrollView *scrollView; +@end + +@implementation SDCAlertViewNew + +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { + self = [self init]; + + if (self) { + _scrollView = [[SDCAlertScrollView alloc] initWithTitle:title message:message]; + [self setTranslatesAutoresizingMaskIntoConstraints:NO]; + } + + return self; +} + +- (void)willMoveToSuperview:(UIView *)newSuperview { + if (!newSuperview) { + return; + } + + [self addSubview:self.scrollView]; + [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; + + [self.scrollView prepareForDisplay]; + +} + +@end From a1af0b9ce4f448b8ef35ef7fd78304193f22c538 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 24 Sep 2014 23:07:42 -0700 Subject: [PATCH 05/76] Use basic collection view for buttons --- SDCAlertView.xcodeproj/project.pbxproj | 24 +++-- SDCAlertView/SDCViewController.m | 4 +- .../Source/SDCAlertCollectionViewCell.h | 15 ++++ .../Source/SDCAlertCollectionViewCell.m | 29 +++++++ SDCAlertView/Source/SDCAlertController.m | 4 +- ...CAlertControllerCollectionViewFlowLayout.h | 13 +++ ...CAlertControllerCollectionViewFlowLayout.m | 13 +++ ...ViewNew.h => SDCAlertRepresentationView.h} | 4 +- .../Source/SDCAlertRepresentationView.m | 87 +++++++++++++++++++ SDCAlertView/Source/SDCAlertViewNew.m | 44 ---------- 10 files changed, 181 insertions(+), 56 deletions(-) create mode 100644 SDCAlertView/Source/SDCAlertCollectionViewCell.h create mode 100644 SDCAlertView/Source/SDCAlertCollectionViewCell.m create mode 100644 SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h create mode 100644 SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m rename SDCAlertView/Source/{SDCAlertViewNew.h => SDCAlertRepresentationView.h} (80%) create mode 100644 SDCAlertView/Source/SDCAlertRepresentationView.m delete mode 100644 SDCAlertView/Source/SDCAlertViewNew.m diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index 0397009f..4ceda5a4 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -29,11 +29,13 @@ D263F1161829D31E0001E4E0 /* SDCAlertViewContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = D263F1151829D31E0001E4E0 /* SDCAlertViewContentView.m */; }; D26506F219C67FC300BF34B9 /* SDCAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F119C67FC300BF34B9 /* SDCAlertController.m */; }; D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F319C6812600BF34B9 /* SDCAlertAction.m */; }; - D2666A4019CFDE2800167157 /* SDCAlertViewNew.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A3F19CFDE2800167157 /* SDCAlertViewNew.m */; }; + D2666A4019CFDE2800167157 /* SDCAlertRepresentationView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A3F19CFDE2800167157 /* SDCAlertRepresentationView.m */; }; D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */; }; D2666A4619CFE0F900167157 /* SDCAlertLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4519CFE0F900167157 /* SDCAlertLabel.m */; }; D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */ = {isa = PBXBuildFile; fileRef = D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */; }; D2A520181840176300837A1A /* SDCAlertView.podspec in Resources */ = {isa = PBXBuildFile; fileRef = D2A520171840176300837A1A /* SDCAlertView.podspec */; }; + D2A5E0D119D3D6A90034B709 /* SDCAlertCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */; }; + D2A6A0DB19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */; }; D2BD0CC418FEB2C400520E33 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC318FEB2C400520E33 /* iPad.storyboard */; }; D2BD0CC618FED65700520E33 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC518FED65700520E33 /* CHANGELOG.md */; }; D2F8345918EF2893000BB281 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = D2F8345718EF2887000BB281 /* Podfile */; }; @@ -89,8 +91,8 @@ D26506F019C67FC300BF34B9 /* SDCAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertController.h; sourceTree = ""; }; D26506F119C67FC300BF34B9 /* SDCAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertController.m; sourceTree = ""; }; D26506F319C6812600BF34B9 /* SDCAlertAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertAction.m; sourceTree = ""; }; - D2666A3E19CFDE2800167157 /* SDCAlertViewNew.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertViewNew.h; sourceTree = ""; }; - D2666A3F19CFDE2800167157 /* SDCAlertViewNew.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertViewNew.m; sourceTree = ""; }; + D2666A3E19CFDE2800167157 /* SDCAlertRepresentationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertRepresentationView.h; sourceTree = ""; }; + D2666A3F19CFDE2800167157 /* SDCAlertRepresentationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertRepresentationView.m; sourceTree = ""; }; D2666A4119CFDF6700167157 /* SDCAlertScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertScrollView.h; sourceTree = ""; }; D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertScrollView.m; sourceTree = ""; }; D2666A4419CFE0F900167157 /* SDCAlertLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertLabel.h; sourceTree = ""; }; @@ -99,6 +101,10 @@ D294876A18D631B700E3D967 /* SDCIntrinsicallySizedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCIntrinsicallySizedView.h; sourceTree = ""; }; D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCIntrinsicallySizedView.m; sourceTree = ""; }; D2A520171840176300837A1A /* SDCAlertView.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SDCAlertView.podspec; sourceTree = ""; }; + D2A5E0CF19D3D6A90034B709 /* SDCAlertCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertCollectionViewCell.h; sourceTree = ""; }; + D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertCollectionViewCell.m; sourceTree = ""; }; + D2A6A0D919D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerCollectionViewFlowLayout.h; sourceTree = ""; }; + D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerCollectionViewFlowLayout.m; sourceTree = ""; }; D2BD0CC318FEB2C400520E33 /* iPad.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = iPad.storyboard; sourceTree = ""; }; D2BD0CC518FED65700520E33 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CHANGELOG.md; sourceTree = ""; }; D2F8345718EF2887000BB281 /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = ""; }; @@ -241,8 +247,12 @@ D26506EF19C61B8000BF34B9 /* 2.0 */ = { isa = PBXGroup; children = ( - D2666A3E19CFDE2800167157 /* SDCAlertViewNew.h */, - D2666A3F19CFDE2800167157 /* SDCAlertViewNew.m */, + D2666A3E19CFDE2800167157 /* SDCAlertRepresentationView.h */, + D2666A3F19CFDE2800167157 /* SDCAlertRepresentationView.m */, + D2A5E0CF19D3D6A90034B709 /* SDCAlertCollectionViewCell.h */, + D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */, + D2A6A0D919D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.h */, + D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */, D2666A4119CFDF6700167157 /* SDCAlertScrollView.h */, D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */, D2666A4419CFE0F900167157 /* SDCAlertLabel.h */, @@ -438,13 +448,15 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D2A5E0D119D3D6A90034B709 /* SDCAlertCollectionViewCell.m in Sources */, D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */, D25B3CB417ECE7A6004B32A2 /* main.m in Sources */, D259FC1519CEB0EB00BA6B36 /* SDCAlertTransition.m in Sources */, D259FC1219CEB02100BA6B36 /* SDCAlertPresentationController.m in Sources */, D25B3CDE17ECF1C5004B32A2 /* SDCAlertView.m in Sources */, D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */, - D2666A4019CFDE2800167157 /* SDCAlertViewNew.m in Sources */, + D2A6A0DB19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m in Sources */, + D2666A4019CFDE2800167157 /* SDCAlertRepresentationView.m in Sources */, D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */, D263F1131829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m in Sources */, D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */, diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 0ba86bc2..3386e867 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -24,9 +24,9 @@ @implementation SDCViewController - (void)presentNow { UIAlertController *b = [UIAlertController alertControllerWithTitle:@"Title 2" message:@"Message 2" preferredStyle:UIAlertControllerStyleAlert]; [b addAction:[UIAlertAction actionWithTitle:@"Button 2" style:UIAlertActionStyleDefault handler:nil]]; - + [b addAction:[UIAlertAction actionWithTitle:@"Button 33??" style:UIAlertActionStyleCancel handler:nil]]; [self presentViewController:b animated:YES completion:^{ - b.title = @""; + }]; } diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.h b/SDCAlertView/Source/SDCAlertCollectionViewCell.h new file mode 100644 index 00000000..d02a18f2 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.h @@ -0,0 +1,15 @@ +// +// SDCAlertCollectionViewCell.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/24/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +@interface SDCAlertCollectionViewCell : UICollectionViewCell + +@property (nonatomic, strong) UILabel *textLabel; + +@end diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m new file mode 100644 index 00000000..92d5d6da --- /dev/null +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -0,0 +1,29 @@ +// +// SDCAlertCollectionViewCell.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/24/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertCollectionViewCell.h" + +@implementation SDCAlertCollectionViewCell + +- (UILabel *)textLabel { + if (!_textLabel) { + _textLabel = [[UILabel alloc] init]; + } + + return _textLabel; +} + + +- (void)layoutSubviews { + [super layoutSubviews]; + + [self.textLabel sizeToFit]; + [self.contentView addSubview:self.textLabel]; +} + +@end diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index d169ed56..cbe863bf 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -9,7 +9,7 @@ #import "SDCAlertController.h" #import "SDCAlertTransition.h" -#import "SDCAlertViewNew.h" +#import "SDCAlertRepresentationView.h" #import "UIView+SDCAutoLayout.h" @interface SDCAlertController () @@ -51,7 +51,7 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref - (void)viewDidLoad { [super viewDidLoad]; - SDCAlertViewNew *alert = [[SDCAlertViewNew alloc] initWithTitle:self.title message:self.message]; + SDCAlertRepresentationView *alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; [alert sdc_pinSize:CGSizeMake(270, 120)]; [self.view addSubview:alert]; diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h new file mode 100644 index 00000000..35a45fd1 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h @@ -0,0 +1,13 @@ +// +// SDCAlertControllerCollectionViewFlowLayout.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/22/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +@interface SDCAlertControllerCollectionViewFlowLayout : UICollectionViewFlowLayout + +@end diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m new file mode 100644 index 00000000..a5faae09 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m @@ -0,0 +1,13 @@ +// +// SDCAlertControllerCollectionViewFlowLayout.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/22/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertControllerCollectionViewFlowLayout.h" + +@implementation SDCAlertControllerCollectionViewFlowLayout + +@end diff --git a/SDCAlertView/Source/SDCAlertViewNew.h b/SDCAlertView/Source/SDCAlertRepresentationView.h similarity index 80% rename from SDCAlertView/Source/SDCAlertViewNew.h rename to SDCAlertView/Source/SDCAlertRepresentationView.h index eb9401f8..30973e2a 100644 --- a/SDCAlertView/Source/SDCAlertViewNew.h +++ b/SDCAlertView/Source/SDCAlertRepresentationView.h @@ -1,5 +1,5 @@ // -// SDCAlertViewNew.h +// SDCAlertRepresentationView.h // SDCAlertView // // Created by Scott Berrevoets on 9/21/14. @@ -8,7 +8,7 @@ #import -@interface SDCAlertViewNew : UIView +@interface SDCAlertRepresentationView : UIView - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m new file mode 100644 index 00000000..a43cbac1 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -0,0 +1,87 @@ +// +// SDCAlertRepresentationView.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/21/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertRepresentationView.h" + +#import "SDCAlertScrollView.h" +#import "SDCAlertControllerCollectionViewFlowLayout.h" +#import "SDCAlertCollectionViewCell.h" + +#import "UIView+SDCAutoLayout.h" + +static NSString *const SDCAlertControllerCellReuseIdentifier = @"SDCAlertControllerCellReuseIdentifier"; + +@interface SDCAlertRepresentationView () +@property (nonatomic, strong) SDCAlertScrollView *scrollView; +@property (nonatomic, strong) UICollectionView *buttonCollectionView; +@property (nonatomic, strong) SDCAlertControllerCollectionViewFlowLayout *collectionViewLayout; +@end + +@implementation SDCAlertRepresentationView + +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { + self = [self init]; + + if (self) { + _scrollView = [[SDCAlertScrollView alloc] initWithTitle:title message:message]; + + _collectionViewLayout = [[SDCAlertControllerCollectionViewFlowLayout alloc] init]; + _buttonCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_collectionViewLayout]; + [_buttonCollectionView setTranslatesAutoresizingMaskIntoConstraints:NO]; + + [_buttonCollectionView registerClass:[SDCAlertCollectionViewCell class] forCellWithReuseIdentifier:SDCAlertControllerCellReuseIdentifier]; + _buttonCollectionView.delegate = self; + _buttonCollectionView.dataSource = self; + _buttonCollectionView.backgroundColor = [UIColor clearColor]; + + [self setTranslatesAutoresizingMaskIntoConstraints:NO]; + } + + return self; +} + +- (void)willMoveToSuperview:(UIView *)newSuperview { + if (!newSuperview) { + return; + } + + [self addSubview:self.scrollView]; + [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; + + [self addSubview:self.buttonCollectionView]; + [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView]; + [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeRight]; + [self.buttonCollectionView sdc_pinHeight:44]; + + [self.scrollView prepareForDisplay]; +} + +#pragma mark - UICollectionViewDelegate + +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { + return 1; +} + +- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { + SDCAlertCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SDCAlertControllerCellReuseIdentifier + forIndexPath:indexPath]; + + cell.textLabel.text = @"button title"; + return cell; +} + +- (CGSize)collectionView:(UICollectionView *)collectionView + layout:(UICollectionViewLayout *)collectionViewLayout + sizeForItemAtIndexPath:(NSIndexPath *)indexPath { + return CGSizeMake(270, 44); +} + + + + +@end diff --git a/SDCAlertView/Source/SDCAlertViewNew.m b/SDCAlertView/Source/SDCAlertViewNew.m deleted file mode 100644 index aa45f834..00000000 --- a/SDCAlertView/Source/SDCAlertViewNew.m +++ /dev/null @@ -1,44 +0,0 @@ -// -// SDCAlertViewNew.m -// SDCAlertView -// -// Created by Scott Berrevoets on 9/21/14. -// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. -// - -#import "SDCAlertViewNew.h" - -#import "SDCAlertScrollView.h" -#import "UIView+SDCAutoLayout.h" - - -@interface SDCAlertViewNew () -@property (nonatomic, strong) SDCAlertScrollView *scrollView; -@end - -@implementation SDCAlertViewNew - -- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { - self = [self init]; - - if (self) { - _scrollView = [[SDCAlertScrollView alloc] initWithTitle:title message:message]; - [self setTranslatesAutoresizingMaskIntoConstraints:NO]; - } - - return self; -} - -- (void)willMoveToSuperview:(UIView *)newSuperview { - if (!newSuperview) { - return; - } - - [self addSubview:self.scrollView]; - [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; - - [self.scrollView prepareForDisplay]; - -} - -@end From 2524c1c525756158ffb682e224191a8c79b74997 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 24 Sep 2014 23:35:48 -0700 Subject: [PATCH 06/76] Use SDCAlertAction to represent items in collection view --- SDCAlertView/SDCViewController.m | 1 + SDCAlertView/Source/SDCAlertController.m | 1 + SDCAlertView/Source/SDCAlertRepresentationView.h | 2 ++ SDCAlertView/Source/SDCAlertRepresentationView.m | 7 +++++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 3386e867..70b761b5 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -34,6 +34,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if (indexPath.section == 0) { SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; + [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDefault handler:nil]]; [self presentViewController:ac animated:YES completion:nil]; //[self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index cbe863bf..3264d82d 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -52,6 +52,7 @@ - (void)viewDidLoad { [super viewDidLoad]; SDCAlertRepresentationView *alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; + alert.actions = self.actions; [alert sdc_pinSize:CGSizeMake(270, 120)]; [self.view addSubview:alert]; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.h b/SDCAlertView/Source/SDCAlertRepresentationView.h index 30973e2a..3c984676 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.h +++ b/SDCAlertView/Source/SDCAlertRepresentationView.h @@ -15,4 +15,6 @@ @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *message; +@property (nonatomic, copy) NSArray *actions; + @end diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index a43cbac1..3b5f873c 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -8,6 +8,7 @@ #import "SDCAlertRepresentationView.h" +#import "SDCAlertController.h" #import "SDCAlertScrollView.h" #import "SDCAlertControllerCollectionViewFlowLayout.h" #import "SDCAlertCollectionViewCell.h" @@ -64,14 +65,16 @@ - (void)willMoveToSuperview:(UIView *)newSuperview { #pragma mark - UICollectionViewDelegate - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { - return 1; + return self.actions.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { SDCAlertCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:SDCAlertControllerCellReuseIdentifier forIndexPath:indexPath]; - cell.textLabel.text = @"button title"; + SDCAlertAction *action = self.actions[indexPath.item]; + cell.textLabel.text = action.title; + return cell; } From aa16fc88ef2ae62b157e06a641635bbba6f3f983 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 24 Sep 2014 23:48:18 -0700 Subject: [PATCH 07/76] Add support for two buttons side by side --- SDCAlertView/SDCViewController.m | 1 + SDCAlertView/Source/SDCAlertCollectionViewCell.m | 5 ++++- .../SDCAlertControllerCollectionViewFlowLayout.m | 10 ++++++++++ SDCAlertView/Source/SDCAlertRepresentationView.m | 8 ++------ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 70b761b5..e9ef58af 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -35,6 +35,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDefault handler:nil]]; + [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:nil]]; [self presentViewController:ac animated:YES completion:nil]; //[self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 92d5d6da..658df0f9 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -8,11 +8,14 @@ #import "SDCAlertCollectionViewCell.h" +#import "UIView+SDCAutoLayout.h" + @implementation SDCAlertCollectionViewCell - (UILabel *)textLabel { if (!_textLabel) { _textLabel = [[UILabel alloc] init]; + [_textLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; } return _textLabel; @@ -22,8 +25,8 @@ - (UILabel *)textLabel { - (void)layoutSubviews { [super layoutSubviews]; - [self.textLabel sizeToFit]; [self.contentView addSubview:self.textLabel]; + [self.textLabel sdc_centerInSuperview]; } @end diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m index a5faae09..f1594dfc 100644 --- a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m @@ -10,4 +10,14 @@ @implementation SDCAlertControllerCollectionViewFlowLayout +- (instancetype)init { + self = [super init]; + + if (self) { + self.minimumInteritemSpacing = 0; + } + + return self; +} + @end diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 3b5f873c..41fbb643 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -74,17 +74,13 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell SDCAlertAction *action = self.actions[indexPath.item]; cell.textLabel.text = action.title; - return cell; } - (CGSize)collectionView:(UICollectionView *)collectionView - layout:(UICollectionViewLayout *)collectionViewLayout +layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { - return CGSizeMake(270, 44); + return CGSizeMake(CGRectGetWidth(self.bounds) / self.actions.count, CGRectGetHeight(collectionView.bounds)); } - - - @end From 185fb45b2ad8da53606cfc2b8808f9dad2a04da5 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Thu, 25 Sep 2014 00:20:32 -0700 Subject: [PATCH 08/76] Utilize system layout mechanisms --- .../Source/SDCAlertRepresentationView.m | 17 +++++++------ SDCAlertView/Source/SDCAlertScrollView.h | 2 -- SDCAlertView/Source/SDCAlertScrollView.m | 25 +++++++++++++------ 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 41fbb643..79224560 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -46,20 +46,21 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { return self; } -- (void)willMoveToSuperview:(UIView *)newSuperview { - if (!newSuperview) { - return; - } - +- (void)layoutSubviews { + [super layoutSubviews]; + [self addSubview:self.scrollView]; - [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; + [self.scrollView setNeedsLayout]; + [self.scrollView layoutIfNeeded]; + + self.scrollView.backgroundColor = [UIColor redColor]; + [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop|UIRectEdgeRight]; + [self.scrollView sdc_setMaximumHeight:76]; [self addSubview:self.buttonCollectionView]; [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView]; [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeRight]; [self.buttonCollectionView sdc_pinHeight:44]; - - [self.scrollView prepareForDisplay]; } #pragma mark - UICollectionViewDelegate diff --git a/SDCAlertView/Source/SDCAlertScrollView.h b/SDCAlertView/Source/SDCAlertScrollView.h index 53e513dc..4f47c4ae 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.h +++ b/SDCAlertView/Source/SDCAlertScrollView.h @@ -12,6 +12,4 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; -- (void)prepareForDisplay; - @end diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index 18c55729..3c8000d7 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -48,7 +48,7 @@ - (void)setTitle:(NSString *)title { _titleLabel.text = title; if (requiresViewHierarchyUpdate && self.superview) { - [self updateViewHierarchy]; + [self setNeedsLayout]; } } @@ -59,15 +59,13 @@ - (void)setMessage:(NSString *)message { _messageLabel.text = message; if (requiresViewHierarchyUpdate && self.superview) { - [self updateViewHierarchy]; + [self setNeedsLayout]; } } -- (void)prepareForDisplay { - [self updateViewHierarchy]; -} - -- (void)updateViewHierarchy { +- (void)layoutSubviews { + [super layoutSubviews]; + if (self.title.length > 0) { [self addSubview:self.titleLabel]; [self.titleLabel sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop]; @@ -89,7 +87,20 @@ - (void)updateViewHierarchy { } else { [self.messageLabel removeFromSuperview]; } + + [self invalidateIntrinsicContentSize]; } +- (CGSize)intrinsicContentSize { + CGFloat intrinsicHeight = 0; + + if (self.message.length > 0) { + intrinsicHeight = CGRectGetMaxY(self.messageLabel.frame) + self.contentInset.top + self.contentInset.bottom; + } else if (self.title.length > 0) { + intrinsicHeight = CGRectGetMaxY(self.titleLabel.frame) + self.contentInset.top + self.contentInset.bottom; + } + + return CGSizeMake(UIViewNoIntrinsicMetric, intrinsicHeight); +} @end From 6590a6a83bc970821e9d64ceafa718f60822196b Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Thu, 25 Sep 2014 21:58:13 -0700 Subject: [PATCH 09/76] Apply basic styling --- SDCAlertView/Source/SDCAlertRepresentationView.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 79224560..e018e0e5 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -9,6 +9,7 @@ #import "SDCAlertRepresentationView.h" #import "SDCAlertController.h" +#import "SDCAlertViewBackgroundView.h" #import "SDCAlertScrollView.h" #import "SDCAlertControllerCollectionViewFlowLayout.h" #import "SDCAlertCollectionViewCell.h" @@ -18,6 +19,7 @@ static NSString *const SDCAlertControllerCellReuseIdentifier = @"SDCAlertControllerCellReuseIdentifier"; @interface SDCAlertRepresentationView () +@property (nonatomic, strong) SDCAlertViewBackgroundView *backgroundView; @property (nonatomic, strong) SDCAlertScrollView *scrollView; @property (nonatomic, strong) UICollectionView *buttonCollectionView; @property (nonatomic, strong) SDCAlertControllerCollectionViewFlowLayout *collectionViewLayout; @@ -40,6 +42,13 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { _buttonCollectionView.dataSource = self; _buttonCollectionView.backgroundColor = [UIColor clearColor]; + _backgroundView = [[SDCAlertViewBackgroundView alloc] init]; + [_backgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; + [self addSubview:_backgroundView]; + + self.layer.masksToBounds = YES; + self.layer.cornerRadius = 5; + [self setTranslatesAutoresizingMaskIntoConstraints:NO]; } @@ -49,11 +58,12 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { - (void)layoutSubviews { [super layoutSubviews]; + [self.backgroundView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; + [self addSubview:self.scrollView]; [self.scrollView setNeedsLayout]; [self.scrollView layoutIfNeeded]; - self.scrollView.backgroundColor = [UIColor redColor]; [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop|UIRectEdgeRight]; [self.scrollView sdc_setMaximumHeight:76]; From 23f699a9d702a67b5563582ef8ca35fb76f9a019 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Fri, 26 Sep 2014 21:06:07 -0700 Subject: [PATCH 10/76] Create background using UIVisualEffectView --- SDCAlertView/SDCViewController.m | 10 +++++----- SDCAlertView/Source/SDCAlertController.m | 14 ++++++++++---- SDCAlertView/Source/SDCAlertRepresentationView.m | 7 ------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index e9ef58af..dd392837 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -22,22 +22,22 @@ @interface SDCViewController () -@property (nonatomic, strong) SDCAlertViewBackgroundView *backgroundView; @property (nonatomic, strong) SDCAlertScrollView *scrollView; @property (nonatomic, strong) UICollectionView *buttonCollectionView; @property (nonatomic, strong) SDCAlertControllerCollectionViewFlowLayout *collectionViewLayout; @@ -42,10 +41,6 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { _buttonCollectionView.dataSource = self; _buttonCollectionView.backgroundColor = [UIColor clearColor]; - _backgroundView = [[SDCAlertViewBackgroundView alloc] init]; - [_backgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; - [self addSubview:_backgroundView]; - self.layer.masksToBounds = YES; self.layer.cornerRadius = 5; @@ -57,8 +52,6 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { - (void)layoutSubviews { [super layoutSubviews]; - - [self.backgroundView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; [self addSubview:self.scrollView]; [self.scrollView setNeedsLayout]; From 4d5d7afb1a0aedb1fdca4f5cdd3fd6596059968c Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Fri, 26 Sep 2014 21:27:19 -0700 Subject: [PATCH 11/76] Move visual effect view to alert representation view --- SDCAlertView/Source/SDCAlertController.m | 13 +++++------- .../Source/SDCAlertRepresentationView.m | 20 ++++++++++++++----- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 06925339..7ce5341e 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -51,19 +51,16 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref - (void)viewDidLoad { [super viewDidLoad]; - UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]; - UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; - [visualEffectView setTranslatesAutoresizingMaskIntoConstraints:NO]; - [visualEffectView sdc_pinSize:CGSizeMake(270, 120)]; SDCAlertRepresentationView *alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; alert.actions = self.actions; - [visualEffectView.contentView addSubview:alert]; - [alert sdc_alignEdgesWithSuperview:UIRectEdgeAll]; + [self.view addSubview:alert]; + //[alert sdc_alignEdgesWithSuperview:UIRectEdgeAll]; + [alert sdc_centerInSuperview]; - [self.view addSubview:visualEffectView]; - [visualEffectView sdc_centerInSuperview]; + [self.view addSubview:alert]; + //[visualEffectView sdc_centerInSuperview]; } #pragma mark - Style diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 89233f25..69fd31b8 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -19,6 +19,7 @@ static NSString *const SDCAlertControllerCellReuseIdentifier = @"SDCAlertControllerCellReuseIdentifier"; @interface SDCAlertRepresentationView () +@property (nonatomic, strong) UIVisualEffectView *visualEffectView; @property (nonatomic, strong) SDCAlertScrollView *scrollView; @property (nonatomic, strong) UICollectionView *buttonCollectionView; @property (nonatomic, strong) SDCAlertControllerCollectionViewFlowLayout *collectionViewLayout; @@ -30,6 +31,12 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { self = [self init]; if (self) { + UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]; + _visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; + _visualEffectView.layer.masksToBounds = YES; + _visualEffectView.layer.cornerRadius = 5; + [_visualEffectView setTranslatesAutoresizingMaskIntoConstraints:NO]; + _scrollView = [[SDCAlertScrollView alloc] initWithTitle:title message:message]; _collectionViewLayout = [[SDCAlertControllerCollectionViewFlowLayout alloc] init]; @@ -40,9 +47,6 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { _buttonCollectionView.delegate = self; _buttonCollectionView.dataSource = self; _buttonCollectionView.backgroundColor = [UIColor clearColor]; - - self.layer.masksToBounds = YES; - self.layer.cornerRadius = 5; [self setTranslatesAutoresizingMaskIntoConstraints:NO]; } @@ -53,17 +57,22 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { - (void)layoutSubviews { [super layoutSubviews]; - [self addSubview:self.scrollView]; + [self.visualEffectView sdc_pinSize:CGSizeMake(270, 120)]; + + [self.visualEffectView.contentView addSubview:self.scrollView]; [self.scrollView setNeedsLayout]; [self.scrollView layoutIfNeeded]; [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop|UIRectEdgeRight]; [self.scrollView sdc_setMaximumHeight:76]; - [self addSubview:self.buttonCollectionView]; + [self.visualEffectView.contentView addSubview:self.buttonCollectionView]; [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView]; [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeRight]; [self.buttonCollectionView sdc_pinHeight:44]; + + [self addSubview:self.visualEffectView]; + [self.visualEffectView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; } #pragma mark - UICollectionViewDelegate @@ -78,6 +87,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell SDCAlertAction *action = self.actions[indexPath.item]; cell.textLabel.text = action.title; + cell.textLabel.textColor = self.tintColor; return cell; } From 639c02387e2e9da58c4485076fcf956f405fae81 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Fri, 26 Sep 2014 21:56:22 -0700 Subject: [PATCH 12/76] Implement basic (dummy) button tapped feedback --- SDCAlertView/SDCViewController.m | 4 +-- .../Source/SDCAlertCollectionViewCell.m | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index dd392837..76c076db 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -36,9 +36,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDefault handler:nil]]; [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:nil]]; [self presentViewController:ac animated:YES completion:nil]; - - - //[self presentNow]; +// [self presentNow]; } else if (indexPath.section == 1) { if (indexPath.row == 0) { diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 658df0f9..4a13ffb3 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -10,23 +10,42 @@ #import "UIView+SDCAutoLayout.h" +@interface SDCAlertCollectionViewCell () +@property (nonatomic, strong) UIView *highlightedBackgroundView; +@end + @implementation SDCAlertCollectionViewCell -- (UILabel *)textLabel { - if (!_textLabel) { +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + + if (self) { + _highlightedBackgroundView = [[UIView alloc] init]; + _highlightedBackgroundView.backgroundColor = [UIColor redColor]; + _highlightedBackgroundView.alpha = 0.5; + _highlightedBackgroundView.hidden = YES; + [_highlightedBackgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; + _textLabel = [[UILabel alloc] init]; [_textLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; } - return _textLabel; + return self; } - - (void)layoutSubviews { [super layoutSubviews]; + [self.contentView addSubview:self.highlightedBackgroundView]; + [self.highlightedBackgroundView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; + [self.contentView addSubview:self.textLabel]; [self.textLabel sdc_centerInSuperview]; } +- (void)setHighlighted:(BOOL)highlighted { + [super setHighlighted:highlighted]; + self.highlightedBackgroundView.hidden = !highlighted; +} + @end From bb22cec5cb92539746f0bc7e958cf983279c60de Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Fri, 26 Sep 2014 22:10:05 -0700 Subject: [PATCH 13/76] Use slightly more realistic highlighted view --- SDCAlertView/Base.lproj/iPhone.storyboard | 7 ++++--- SDCAlertView/Source/SDCAlertCollectionViewCell.m | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SDCAlertView/Base.lproj/iPhone.storyboard b/SDCAlertView/Base.lproj/iPhone.storyboard index d441be1a..5129ac59 100644 --- a/SDCAlertView/Base.lproj/iPhone.storyboard +++ b/SDCAlertView/Base.lproj/iPhone.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -170,7 +171,7 @@ - + diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 4a13ffb3..1d451f88 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -21,8 +21,7 @@ - (instancetype)initWithFrame:(CGRect)frame { if (self) { _highlightedBackgroundView = [[UIView alloc] init]; - _highlightedBackgroundView.backgroundColor = [UIColor redColor]; - _highlightedBackgroundView.alpha = 0.5; + _highlightedBackgroundView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.3]; _highlightedBackgroundView.hidden = YES; [_highlightedBackgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; From 41aec5075fd19fc089463a1b7811ba9189eb58c6 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Fri, 26 Sep 2014 23:16:06 -0700 Subject: [PATCH 14/76] Use decoration views for button separators --- .../Source/SDCAlertCollectionViewCell.h | 6 ++-- .../Source/SDCAlertCollectionViewCell.m | 14 ++++++++ ...CAlertControllerCollectionViewFlowLayout.m | 33 ++++++++++++++++++- .../Source/SDCAlertRepresentationView.m | 2 ++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.h b/SDCAlertView/Source/SDCAlertCollectionViewCell.h index d02a18f2..38e45a4c 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.h +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.h @@ -8,8 +8,10 @@ #import -@interface SDCAlertCollectionViewCell : UICollectionViewCell +@interface SDCAlertControllerSeparatorView : UICollectionReusableView +@end -@property (nonatomic, strong) UILabel *textLabel; +@interface SDCAlertCollectionViewCell : UICollectionViewCell +@property (nonatomic, strong) UILabel *textLabel; @end diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 1d451f88..0beceed4 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -48,3 +48,17 @@ - (void)setHighlighted:(BOOL)highlighted { } @end + +@implementation SDCAlertControllerSeparatorView + +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + + if (self) { + self.backgroundColor = [UIColor grayColor]; + } + + return self; +} + +@end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m index f1594dfc..0eb2d256 100644 --- a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m @@ -20,4 +20,35 @@ - (instancetype)init { return self; } -@end +- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { + NSMutableArray *attributes = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; + + [[attributes copy] enumerateObjectsUsingBlock:^(UICollectionViewLayoutAttributes *itemAttributes, NSUInteger idx, BOOL *stop) { + [attributes addObject:[self layoutAttributesForDecorationViewOfKind:@"separator" atIndexPath:itemAttributes.indexPath]]; + }]; + + UICollectionViewLayoutAttributes *topSeparatorAttributes = [UICollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:@"separator" + withIndexPath:nil]; + topSeparatorAttributes.frame = CGRectMake(CGRectGetMinX(rect), CGRectGetMinY(rect), CGRectGetWidth(rect), 0.5); + + [attributes addObject:topSeparatorAttributes]; + + return attributes; +} + +- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { + return [super layoutAttributesForItemAtIndexPath:indexPath]; +} + +- (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { + UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:elementKind + withIndexPath:indexPath]; + + UICollectionViewLayoutAttributes *itemAttributes = [self layoutAttributesForItemAtIndexPath:indexPath]; + attributes.frame = CGRectMake(CGRectGetMaxX(itemAttributes.frame) - 0.5, CGRectGetMinY(itemAttributes.frame), 0.5, CGRectGetHeight(itemAttributes.frame)); + attributes.zIndex = itemAttributes.zIndex + 1; + + return attributes; +} + +@end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 69fd31b8..dfe535ce 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -44,6 +44,8 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { [_buttonCollectionView setTranslatesAutoresizingMaskIntoConstraints:NO]; [_buttonCollectionView registerClass:[SDCAlertCollectionViewCell class] forCellWithReuseIdentifier:SDCAlertControllerCellReuseIdentifier]; + [_buttonCollectionView.collectionViewLayout registerClass:[SDCAlertControllerSeparatorView class] forDecorationViewOfKind:@"separator"]; + _buttonCollectionView.delegate = self; _buttonCollectionView.dataSource = self; _buttonCollectionView.backgroundColor = [UIColor clearColor]; From 7607f204d4f0b8fcb1ab1784990239c0dac68755 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 27 Sep 2014 18:16:36 -0700 Subject: [PATCH 15/76] Lay out groundwork for visual styles --- SDCAlertView.xcodeproj/project.pbxproj | 8 ++++++++ SDCAlertView/Source/SDCAlertController.h | 6 +++++- SDCAlertView/Source/SDCAlertController.m | 10 +++++----- .../SDCAlertControllerCollectionViewFlowLayout.h | 4 +++- .../Source/SDCAlertControllerDefaultVisualStyle.h | 15 +++++++++++++++ .../Source/SDCAlertControllerDefaultVisualStyle.m | 13 +++++++++++++ .../Source/SDCAlertControllerVisualStyle.h | 13 +++++++++++++ SDCAlertView/Source/SDCAlertRepresentationView.h | 4 ++++ SDCAlertView/Source/SDCAlertRepresentationView.m | 7 +++++++ SDCAlertView/Source/SDCAlertScrollView.h | 2 ++ 10 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.h create mode 100644 SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m create mode 100644 SDCAlertView/Source/SDCAlertControllerVisualStyle.h diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index 4ceda5a4..f7e93ee2 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -33,6 +33,7 @@ D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */; }; D2666A4619CFE0F900167157 /* SDCAlertLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4519CFE0F900167157 /* SDCAlertLabel.m */; }; D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */ = {isa = PBXBuildFile; fileRef = D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */; }; + D2988E0319D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = D2988E0219D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m */; }; D2A520181840176300837A1A /* SDCAlertView.podspec in Resources */ = {isa = PBXBuildFile; fileRef = D2A520171840176300837A1A /* SDCAlertView.podspec */; }; D2A5E0D119D3D6A90034B709 /* SDCAlertCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */; }; D2A6A0DB19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */; }; @@ -100,6 +101,9 @@ D268093118F845420001B7E9 /* SDCAlertViewTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCAlertViewTransitioning.h; sourceTree = ""; }; D294876A18D631B700E3D967 /* SDCIntrinsicallySizedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCIntrinsicallySizedView.h; sourceTree = ""; }; D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCIntrinsicallySizedView.m; sourceTree = ""; }; + D2988E0119D794C100140116 /* SDCAlertControllerDefaultVisualStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerDefaultVisualStyle.h; sourceTree = ""; }; + D2988E0219D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerDefaultVisualStyle.m; sourceTree = ""; }; + D2988E0519D7960900140116 /* SDCAlertControllerVisualStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerVisualStyle.h; sourceTree = ""; }; D2A520171840176300837A1A /* SDCAlertView.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SDCAlertView.podspec; sourceTree = ""; }; D2A5E0CF19D3D6A90034B709 /* SDCAlertCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertCollectionViewCell.h; sourceTree = ""; }; D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertCollectionViewCell.m; sourceTree = ""; }; @@ -247,6 +251,7 @@ D26506EF19C61B8000BF34B9 /* 2.0 */ = { isa = PBXGroup; children = ( + D2988E0519D7960900140116 /* SDCAlertControllerVisualStyle.h */, D2666A3E19CFDE2800167157 /* SDCAlertRepresentationView.h */, D2666A3F19CFDE2800167157 /* SDCAlertRepresentationView.m */, D2A5E0CF19D3D6A90034B709 /* SDCAlertCollectionViewCell.h */, @@ -263,6 +268,8 @@ D259FC1419CEB0EB00BA6B36 /* SDCAlertTransition.m */, D26506F019C67FC300BF34B9 /* SDCAlertController.h */, D26506F119C67FC300BF34B9 /* SDCAlertController.m */, + D2988E0119D794C100140116 /* SDCAlertControllerDefaultVisualStyle.h */, + D2988E0219D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m */, D26506F319C6812600BF34B9 /* SDCAlertAction.m */, ); name = 2.0; @@ -452,6 +459,7 @@ D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */, D25B3CB417ECE7A6004B32A2 /* main.m in Sources */, D259FC1519CEB0EB00BA6B36 /* SDCAlertTransition.m in Sources */, + D2988E0319D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m in Sources */, D259FC1219CEB02100BA6B36 /* SDCAlertPresentationController.m in Sources */, D25B3CDE17ECF1C5004B32A2 /* SDCAlertView.m in Sources */, D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */, diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index cfb065d6..397d4909 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -28,6 +28,8 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerStyle) { @end +@protocol SDCAlertControllerVisualStyle; + @interface SDCAlertController : UIViewController + (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(SDCAlertControllerStyle)preferredStyle; @@ -42,4 +44,6 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerStyle) { @property (nonatomic, readonly) SDCAlertControllerStyle preferredStyle; -@end +- (void)applyVisualStyle:(id)visualStyle; + +@end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 7ce5341e..04bba562 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -16,6 +16,7 @@ @interface SDCAlertController () @property (nonatomic, strong) NSMutableArray *mutableActions; @property (nonatomic, strong) NSMutableArray *textFieldConfigurationHandlers; @property (nonatomic, strong) id transitioningDelegate; +@property (nonatomic, strong) id visualStyle; @end @implementation SDCAlertController @@ -51,16 +52,13 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref - (void)viewDidLoad { [super viewDidLoad]; - SDCAlertRepresentationView *alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; alert.actions = self.actions; [self.view addSubview:alert]; - //[alert sdc_alignEdgesWithSuperview:UIRectEdgeAll]; [alert sdc_centerInSuperview]; [self.view addSubview:alert]; - //[visualEffectView sdc_centerInSuperview]; } #pragma mark - Style @@ -69,6 +67,10 @@ - (SDCAlertControllerStyle)preferredStyle { return SDCAlertControllerStyleAlert; } +- (void)applyVisualStyle:(id)visualStyle { + _visualStyle = visualStyle; +} + #pragma mark - Alert Actions - (void)addAction:(SDCAlertAction *)action { @@ -89,6 +91,4 @@ - (NSArray *)textFields { return [NSArray array]; } - - @end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h index 35a45fd1..d861a3b8 100644 --- a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h @@ -6,8 +6,10 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; @interface SDCAlertControllerCollectionViewFlowLayout : UICollectionViewFlowLayout +@property (nonatomic, strong) id visualStyle; + @end diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.h new file mode 100644 index 00000000..a56665e1 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.h @@ -0,0 +1,15 @@ +// +// SDCAlertControllerDefaultVisualStyle.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/27/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +#import "SDCAlertControllerVisualStyle.h" + +@interface SDCAlertControllerDefaultVisualStyle : NSObject + +@end diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m new file mode 100644 index 00000000..95681403 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -0,0 +1,13 @@ +// +// SDCAlertControllerDefaultVisualStyle.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/27/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertControllerDefaultVisualStyle.h" + +@implementation SDCAlertControllerDefaultVisualStyle + +@end diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h new file mode 100644 index 00000000..7387ebcd --- /dev/null +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -0,0 +1,13 @@ +// +// SDCAlertControllerVisualStyle.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/27/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +@protocol SDCAlertControllerVisualStyle + +@end diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.h b/SDCAlertView/Source/SDCAlertRepresentationView.h index 3c984676..44dd235f 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.h +++ b/SDCAlertView/Source/SDCAlertRepresentationView.h @@ -8,6 +8,8 @@ #import +@protocol SDCAlertControllerVisualStyle; + @interface SDCAlertRepresentationView : UIView - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; @@ -17,4 +19,6 @@ @property (nonatomic, copy) NSArray *actions; +@property (nonatomic, strong) id visualStyle; + @end diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index dfe535ce..049c1e95 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -59,6 +59,8 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { - (void)layoutSubviews { [super layoutSubviews]; + [self applyCurrentStyleToAlertElements]; + [self.visualEffectView sdc_pinSize:CGSizeMake(270, 120)]; [self.visualEffectView.contentView addSubview:self.scrollView]; @@ -77,6 +79,11 @@ - (void)layoutSubviews { [self.visualEffectView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; } +- (void)applyCurrentStyleToAlertElements { + self.scrollView.visualStyle = self.visualStyle; + self.collectionViewLayout.visualStyle = self.visualStyle; +} + #pragma mark - UICollectionViewDelegate - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { diff --git a/SDCAlertView/Source/SDCAlertScrollView.h b/SDCAlertView/Source/SDCAlertScrollView.h index 4f47c4ae..5d7db5f3 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.h +++ b/SDCAlertView/Source/SDCAlertScrollView.h @@ -10,6 +10,8 @@ @interface SDCAlertScrollView : UIScrollView +@property (nonatomic, strong) id visualStyle; + - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; @end From b2b4bfe4b19826ea784768bf13813dd279fcc3fa Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 27 Sep 2014 19:23:20 -0700 Subject: [PATCH 16/76] Congregate visual styles used so far --- .../Source/SDCAlertCollectionViewCell.h | 3 +++ .../Source/SDCAlertCollectionViewCell.m | 15 +++++++---- SDCAlertView/Source/SDCAlertController.m | 5 ++++ ...CAlertControllerCollectionViewFlowLayout.h | 2 ++ .../SDCAlertControllerDefaultVisualStyle.m | 26 +++++++++++++++++++ .../Source/SDCAlertControllerVisualStyle.h | 10 +++++++ .../Source/SDCAlertRepresentationView.m | 7 ++--- SDCAlertView/Source/SDCAlertScrollView.h | 2 ++ SDCAlertView/Source/SDCAlertScrollView.m | 23 +++++++++------- 9 files changed, 75 insertions(+), 18 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.h b/SDCAlertView/Source/SDCAlertCollectionViewCell.h index 38e45a4c..3a83af51 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.h +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.h @@ -8,10 +8,13 @@ #import +#import "SDCAlertControllerVisualStyle.h" + @interface SDCAlertControllerSeparatorView : UICollectionReusableView @end @interface SDCAlertCollectionViewCell : UICollectionViewCell +@property (nonatomic, strong) id visualStyle; @property (nonatomic, strong) UILabel *textLabel; @end diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 0beceed4..878f2ce8 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -20,11 +20,6 @@ - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - _highlightedBackgroundView = [[UIView alloc] init]; - _highlightedBackgroundView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.3]; - _highlightedBackgroundView.hidden = YES; - [_highlightedBackgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; - _textLabel = [[UILabel alloc] init]; [_textLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; } @@ -32,6 +27,16 @@ - (instancetype)initWithFrame:(CGRect)frame { return self; } +- (void)setVisualStyle:(id)visualStyle { + _visualStyle = visualStyle; + + self.highlightedBackgroundView = visualStyle.buttonHighlightBackgroundView; + [self.highlightedBackgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; + self.highlightedBackgroundView.hidden = !self.isHighlighted; + + self.textLabel.textColor = self.visualStyle.buttonTextColor; +} + - (void)layoutSubviews { [super layoutSubviews]; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 04bba562..ca63c929 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -10,6 +10,8 @@ #import "SDCAlertTransition.h" #import "SDCAlertRepresentationView.h" +#import "SDCAlertControllerDefaultVisualStyle.h" + #import "UIView+SDCAutoLayout.h" @interface SDCAlertController () @@ -40,6 +42,8 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref _mutableActions = [NSMutableArray array]; _textFieldConfigurationHandlers = [NSMutableArray array]; + _visualStyle = [[SDCAlertControllerDefaultVisualStyle alloc] init]; + self.modalPresentationStyle = UIModalPresentationCustom; self.transitioningDelegate = [[SDCAlertTransitioningDelegate alloc] init]; } @@ -53,6 +57,7 @@ - (void)viewDidLoad { [super viewDidLoad]; SDCAlertRepresentationView *alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; + alert.visualStyle = self.visualStyle; alert.actions = self.actions; [self.view addSubview:alert]; diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h index d861a3b8..4c963be3 100644 --- a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h @@ -8,6 +8,8 @@ @import UIKit; +#import "SDCAlertControllerVisualStyle.h" + @interface SDCAlertControllerCollectionViewFlowLayout : UICollectionViewFlowLayout @property (nonatomic, strong) id visualStyle; diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index 95681403..6836188f 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -10,4 +10,30 @@ @implementation SDCAlertControllerDefaultVisualStyle +- (CGFloat)width { + return 270; +} + +- (CGFloat)buttonHeight { + return 44; +} + +- (UIEdgeInsets)contentPadding { + return UIEdgeInsetsMake(19, 15, 18.5, 15); +} + +- (CGFloat)labelSpacing { + return 4; +} + +- (UIView *)buttonHighlightBackgroundView { + UIView *view = [[UIView alloc] init]; + view.backgroundColor = [UIColor colorWithWhite:.80 alpha:.7]; + return view; +} + +- (UIColor *)buttonTextColor { + return [[[UIView alloc] init] tintColor]; +} + @end diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index 7387ebcd..419f95ee 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -10,4 +10,14 @@ @protocol SDCAlertControllerVisualStyle +@property (nonatomic, readonly) CGFloat width; +@property (nonatomic, readonly) CGFloat buttonHeight; + +@property (nonatomic, readonly) UIEdgeInsets contentPadding; +@property (nonatomic, readonly) CGFloat labelSpacing; + + +@property (nonatomic, readonly) UIView *buttonHighlightBackgroundView; +@property (nonatomic, readonly) UIColor *buttonTextColor; + @end diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 049c1e95..c529fcf9 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -61,7 +61,7 @@ - (void)layoutSubviews { [self applyCurrentStyleToAlertElements]; - [self.visualEffectView sdc_pinSize:CGSizeMake(270, 120)]; + [self.visualEffectView sdc_pinSize:CGSizeMake(self.visualStyle.width, 120)]; [self.visualEffectView.contentView addSubview:self.scrollView]; [self.scrollView setNeedsLayout]; @@ -73,7 +73,7 @@ - (void)layoutSubviews { [self.visualEffectView.contentView addSubview:self.buttonCollectionView]; [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView]; [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeRight]; - [self.buttonCollectionView sdc_pinHeight:44]; + [self.buttonCollectionView sdc_pinHeight:self.visualStyle.buttonHeight]; [self addSubview:self.visualEffectView]; [self.visualEffectView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; @@ -95,8 +95,9 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell forIndexPath:indexPath]; SDCAlertAction *action = self.actions[indexPath.item]; + cell.visualStyle = self.visualStyle; cell.textLabel.text = action.title; - cell.textLabel.textColor = self.tintColor; + return cell; } diff --git a/SDCAlertView/Source/SDCAlertScrollView.h b/SDCAlertView/Source/SDCAlertScrollView.h index 5d7db5f3..a5c6cfd4 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.h +++ b/SDCAlertView/Source/SDCAlertScrollView.h @@ -8,6 +8,8 @@ @import UIKit; +#import "SDCAlertControllerVisualStyle.h" + @interface SDCAlertScrollView : UIScrollView @property (nonatomic, strong) id visualStyle; diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index 3c8000d7..9fa6c396 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -10,9 +10,6 @@ #import "SDCAlertLabel.h" #import "UIView+SDCAutoLayout.h" -static UIEdgeInsets const SDCAlertScrollViewInsets = {19, 15, 18.5, 15}; -static CGFloat const SDCAlertScrollViewLabelSpacing = 4; - @interface SDCAlertScrollView () @property (nonatomic, strong) NSString *title; @property (nonatomic, strong) SDCAlertLabel *titleLabel; @@ -32,9 +29,6 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { self.title = title; self.message = message; - self.contentInset = SDCAlertScrollViewInsets; - self.scrollIndicatorInsets = SDCAlertScrollViewInsets; - [self setTranslatesAutoresizingMaskIntoConstraints:NO]; } @@ -63,13 +57,22 @@ - (void)setMessage:(NSString *)message { } } +- (void)setVisualStyle:(id)visualStyle { + _visualStyle = visualStyle; + + self.contentInset = visualStyle.contentPadding; + self.scrollIndicatorInsets = visualStyle.contentPadding; + + [self setNeedsLayout]; +} + - (void)layoutSubviews { [super layoutSubviews]; if (self.title.length > 0) { [self addSubview:self.titleLabel]; [self.titleLabel sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop]; - [self.titleLabel sdc_pinWidthToWidthOfView:self offset:-(SDCAlertScrollViewInsets.left + SDCAlertScrollViewInsets.right)]; + [self.titleLabel sdc_pinWidthToWidthOfView:self offset:-(self.visualStyle.contentPadding.left + self.visualStyle.contentPadding.right)]; } else { [self.titleLabel removeFromSuperview]; } @@ -77,12 +80,12 @@ - (void)layoutSubviews { if (self.message.length > 0) { [self addSubview:self.messageLabel]; [self.messageLabel sdc_alignEdgesWithSuperview:UIRectEdgeLeft]; - [self.messageLabel sdc_pinWidthToWidthOfView:self offset:-(SDCAlertScrollViewInsets.left + SDCAlertScrollViewInsets.right)]; + [self.messageLabel sdc_pinWidthToWidthOfView:self offset:-(self.visualStyle.contentPadding.left + self.visualStyle.contentPadding.right)]; if (self.title.length > 0) { - [self.messageLabel sdc_pinVerticalSpacing:SDCAlertScrollViewLabelSpacing toView:self.titleLabel]; + [self.messageLabel sdc_pinVerticalSpacing:self.visualStyle.labelSpacing toView:self.titleLabel]; } else { - [self.messageLabel sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeTop ofView:self inset:SDCAlertScrollViewLabelSpacing]; + [self.messageLabel sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeTop ofView:self inset:self.visualStyle.labelSpacing]; } } else { [self.messageLabel removeFromSuperview]; From cbc13cf6683fe596d7bcadb987a22fc0f3659dbe Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 27 Sep 2014 19:28:16 -0700 Subject: [PATCH 17/76] Use visual styles for title and message labels --- .../Source/SDCAlertControllerDefaultVisualStyle.m | 8 ++++++++ SDCAlertView/Source/SDCAlertControllerVisualStyle.h | 3 +++ SDCAlertView/Source/SDCAlertScrollView.m | 3 +++ 3 files changed, 14 insertions(+) diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index 6836188f..6f4a421a 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -36,4 +36,12 @@ - (UIColor *)buttonTextColor { return [[[UIView alloc] init] tintColor]; } +- (UIFont *)titleLabelFont { + return [UIFont boldSystemFontOfSize:17]; +} + +- (UIFont *)messageLabelFont { + return [UIFont systemFontOfSize:14]; +} + @end diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index 419f95ee..b4b62d5f 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -20,4 +20,7 @@ @property (nonatomic, readonly) UIView *buttonHighlightBackgroundView; @property (nonatomic, readonly) UIColor *buttonTextColor; +@property (nonatomic, readonly) UIFont *titleLabelFont; +@property (nonatomic, readonly) UIFont *messageLabelFont; + @end diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index 9fa6c396..0da6a506 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -63,6 +63,9 @@ - (void)setVisualStyle:(id)visualStyle { self.contentInset = visualStyle.contentPadding; self.scrollIndicatorInsets = visualStyle.contentPadding; + self.titleLabel.font = visualStyle.titleLabelFont; + self.messageLabel.font = visualStyle.messageLabelFont; + [self setNeedsLayout]; } From cbe93744caab27c9eee308bb17268da410488a78 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 27 Sep 2014 20:00:41 -0700 Subject: [PATCH 18/76] Use alert actions for alert dismissal --- SDCAlertView/SDCViewController.m | 4 +++- SDCAlertView/Source/SDCAlertAction.m | 1 + .../Source/SDCAlertCollectionViewCell.h | 2 ++ .../Source/SDCAlertCollectionViewCell.m | 7 +++++++ SDCAlertView/Source/SDCAlertController.m | 19 ++++++++++++++++++- .../Source/SDCAlertRepresentationView.h | 13 +++++++++++-- .../Source/SDCAlertRepresentationView.m | 9 +++++++++ 7 files changed, 51 insertions(+), 4 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 76c076db..dbe1bc0d 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -34,7 +34,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath if (indexPath.section == 0) { SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDefault handler:nil]]; - [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:nil]]; + [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:^(SDCAlertAction *action) { + NSLog(@"%@", action.title); + }]]; [self presentViewController:ac animated:YES completion:nil]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertAction.m b/SDCAlertView/Source/SDCAlertAction.m index 287c9919..398a44cb 100644 --- a/SDCAlertView/Source/SDCAlertAction.m +++ b/SDCAlertView/Source/SDCAlertAction.m @@ -27,6 +27,7 @@ - (instancetype)initWithTitle:(NSString *)title style:(SDCAlertActionStyle)style if (self) { _title = title; _style = style; + _enabled = YES; _handler = handler; } diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.h b/SDCAlertView/Source/SDCAlertCollectionViewCell.h index 3a83af51..c3e94458 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.h +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.h @@ -17,4 +17,6 @@ @interface SDCAlertCollectionViewCell : UICollectionViewCell @property (nonatomic, strong) id visualStyle; @property (nonatomic, strong) UILabel *textLabel; + +@property (nonatomic, strong) UIGestureRecognizer *gestureRecognizer; @end diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 878f2ce8..ca6f6ff7 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -37,6 +37,13 @@ - (void)setVisualStyle:(id)visualStyle { self.textLabel.textColor = self.visualStyle.buttonTextColor; } +- (void)setGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { + [self removeGestureRecognizer:_gestureRecognizer]; + + _gestureRecognizer = gestureRecognizer; + [self addGestureRecognizer:gestureRecognizer]; +} + - (void)layoutSubviews { [super layoutSubviews]; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index ca63c929..f8177f55 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -14,7 +14,11 @@ #import "UIView+SDCAutoLayout.h" -@interface SDCAlertController () +@interface SDCAlertAction (Private) +@property (nonatomic, copy) void (^handler)(SDCAlertAction *); +@end + +@interface SDCAlertController () @property (nonatomic, strong) NSMutableArray *mutableActions; @property (nonatomic, strong) NSMutableArray *textFieldConfigurationHandlers; @property (nonatomic, strong) id transitioningDelegate; @@ -57,6 +61,7 @@ - (void)viewDidLoad { [super viewDidLoad]; SDCAlertRepresentationView *alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; + alert.delegate = self; alert.visualStyle = self.visualStyle; alert.actions = self.actions; @@ -86,6 +91,18 @@ - (NSArray *)actions { return [self.mutableActions copy]; } +- (void)alertRepresentationView:(SDCAlertRepresentationView *)sender didPerformAction:(SDCAlertAction *)action { + if (!action.isEnabled) { + return; + } + + [self.presentingViewController dismissViewControllerAnimated:YES completion:^{ + if (action.handler) { + action.handler(action); + } + }]; +} + #pragma mark - Alert Text Fields - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *))configurationHandler { diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.h b/SDCAlertView/Source/SDCAlertRepresentationView.h index 44dd235f..9a82e57c 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.h +++ b/SDCAlertView/Source/SDCAlertRepresentationView.h @@ -6,13 +6,20 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; + +@class SDCAlertRepresentationView; +@class SDCAlertAction; + +@protocol SDCAlertRepresentationViewDelegate +- (void)alertRepresentationView:(SDCAlertRepresentationView *)sender didPerformAction:(SDCAlertAction *)action; +@end @protocol SDCAlertControllerVisualStyle; @interface SDCAlertRepresentationView : UIView -- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; +@property (nonatomic, weak) id delegate; @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *message; @@ -21,4 +28,6 @@ @property (nonatomic, strong) id visualStyle; +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; + @end diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index c529fcf9..ebe038ab 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -84,6 +84,14 @@ - (void)applyCurrentStyleToAlertElements { self.collectionViewLayout.visualStyle = self.visualStyle; } +- (void)actionButtonTapped:(UITapGestureRecognizer *)sender { + SDCAlertCollectionViewCell *cell = (SDCAlertCollectionViewCell *)sender.view; + NSIndexPath *indexPath = [self.buttonCollectionView indexPathForCell:cell]; + SDCAlertAction *action = self.actions[indexPath.row]; + + [self.delegate alertRepresentationView:self didPerformAction:action]; +} + #pragma mark - UICollectionViewDelegate - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { @@ -97,6 +105,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell SDCAlertAction *action = self.actions[indexPath.item]; cell.visualStyle = self.visualStyle; cell.textLabel.text = action.title; + cell.gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionButtonTapped:)]; return cell; } From b598d3c796ed41e5401f40674f2cea57c2a9e6d8 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 27 Sep 2014 20:10:35 -0700 Subject: [PATCH 19/76] Correctly represent action states in alert buttons --- SDCAlertView/SDCViewController.m | 4 ++-- .../Source/SDCAlertCollectionViewCell.m | 2 -- .../SDCAlertControllerDefaultVisualStyle.m | 22 +++++++++++++++---- .../Source/SDCAlertControllerVisualStyle.h | 8 +++++-- .../Source/SDCAlertRepresentationView.m | 4 ++++ 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index dbe1bc0d..9e96c758 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -33,8 +33,8 @@ - (void)presentNow { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; - [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDefault handler:nil]]; - [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:^(SDCAlertAction *action) { + [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:nil]]; + [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { NSLog(@"%@", action.title); }]]; [self presentViewController:ac animated:YES completion:nil]; diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index ca6f6ff7..83d2553d 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -33,8 +33,6 @@ - (void)setVisualStyle:(id)visualStyle { self.highlightedBackgroundView = visualStyle.buttonHighlightBackgroundView; [self.highlightedBackgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; self.highlightedBackgroundView.hidden = !self.isHighlighted; - - self.textLabel.textColor = self.visualStyle.buttonTextColor; } - (void)setGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index 6f4a421a..b98b1313 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -8,6 +8,8 @@ #import "SDCAlertControllerDefaultVisualStyle.h" +#import "SDCAlertController.h" + @implementation SDCAlertControllerDefaultVisualStyle - (CGFloat)width { @@ -32,10 +34,6 @@ - (UIView *)buttonHighlightBackgroundView { return view; } -- (UIColor *)buttonTextColor { - return [[[UIView alloc] init] tintColor]; -} - - (UIFont *)titleLabelFont { return [UIFont boldSystemFontOfSize:17]; } @@ -44,4 +42,20 @@ - (UIFont *)messageLabelFont { return [UIFont systemFontOfSize:14]; } +- (UIColor *)textColorForButtonRepresentingAction:(SDCAlertAction *)action { + if (action.style == SDCAlertActionStyleDestructive) { + return [UIColor redColor]; + } else { + return [[[UIView alloc] init] tintColor]; + } +} + +- (UIFont *)fontForButtonRepresentingAction:(SDCAlertAction *)action { + if (action.style == SDCAlertActionStyleCancel) { + return [UIFont boldSystemFontOfSize:17]; + } else { + return [UIFont systemFontOfSize:17]; + } +} + @end diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index b4b62d5f..f4089240 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -6,7 +6,9 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import Foundation; + +@class SDCAlertAction; @protocol SDCAlertControllerVisualStyle @@ -18,9 +20,11 @@ @property (nonatomic, readonly) UIView *buttonHighlightBackgroundView; -@property (nonatomic, readonly) UIColor *buttonTextColor; @property (nonatomic, readonly) UIFont *titleLabelFont; @property (nonatomic, readonly) UIFont *messageLabelFont; +- (UIColor *)textColorForButtonRepresentingAction:(SDCAlertAction *)action; +- (UIFont *)fontForButtonRepresentingAction:(SDCAlertAction *)action; + @end diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index ebe038ab..56e82bec 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -104,7 +104,11 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell SDCAlertAction *action = self.actions[indexPath.item]; cell.visualStyle = self.visualStyle; + cell.textLabel.font = [self.visualStyle fontForButtonRepresentingAction:action]; cell.textLabel.text = action.title; + cell.textLabel.textColor = [self.visualStyle textColorForButtonRepresentingAction:action]; + cell.textLabel.enabled = action.isEnabled; + cell.gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionButtonTapped:)]; return cell; From e4917e80d351f23fc87ef8a2ad88694fbc36991f Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 27 Sep 2014 20:54:35 -0700 Subject: [PATCH 20/76] Dynamically calculate scroll view height --- SDCAlertView/SDCViewController.m | 2 +- SDCAlertView/Source/SDCAlertController.m | 15 ++++++----- .../SDCAlertControllerDefaultVisualStyle.m | 4 +++ .../Source/SDCAlertControllerVisualStyle.h | 1 + .../Source/SDCAlertRepresentationView.m | 26 +++++++++++++++---- SDCAlertView/Source/SDCAlertScrollView.m | 7 ++--- 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 9e96c758..1119e328 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -32,7 +32,7 @@ - (void)presentNow { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { - SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; + SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"MessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessage" preferredStyle:SDCAlertControllerStyleAlert]; [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:nil]]; [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { NSLog(@"%@", action.title); diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index f8177f55..ae5c5222 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -23,6 +23,7 @@ @interface SDCAlertController () @property (nonatomic, strong) NSMutableArray *textFieldConfigurationHandlers; @property (nonatomic, strong) id transitioningDelegate; @property (nonatomic, strong) id visualStyle; +@property (nonatomic, strong) SDCAlertRepresentationView *alert; @end @implementation SDCAlertController @@ -60,15 +61,15 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref - (void)viewDidLoad { [super viewDidLoad]; - SDCAlertRepresentationView *alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; - alert.delegate = self; - alert.visualStyle = self.visualStyle; - alert.actions = self.actions; + self.alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; + self.alert.delegate = self; + self.alert.visualStyle = self.visualStyle; + self.alert.actions = self.actions; - [self.view addSubview:alert]; - [alert sdc_centerInSuperview]; + [self.view addSubview:self.alert]; + [self.alert sdc_centerInSuperview]; - [self.view addSubview:alert]; + [self.view addSubview:self.alert]; } #pragma mark - Style diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index b98b1313..89b3f754 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -20,6 +20,10 @@ - (CGFloat)buttonHeight { return 44; } +- (UIEdgeInsets)margins { + return UIEdgeInsetsMake(3, 0, 3, 0); +} + - (UIEdgeInsets)contentPadding { return UIEdgeInsetsMake(19, 15, 18.5, 15); } diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index f4089240..ec089882 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -15,6 +15,7 @@ @property (nonatomic, readonly) CGFloat width; @property (nonatomic, readonly) CGFloat buttonHeight; +@property (nonatomic, readonly) UIEdgeInsets margins; @property (nonatomic, readonly) UIEdgeInsets contentPadding; @property (nonatomic, readonly) CGFloat labelSpacing; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 56e82bec..9b651f5f 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -56,23 +56,39 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { return self; } +- (CGFloat)maximumHeightForScrollView { + CGFloat maximumHeight = CGRectGetHeight(self.superview.bounds) - self.visualStyle.margins.top - self.visualStyle.margins.bottom; + maximumHeight -= self.visualStyle.contentPadding.top - self.visualStyle.contentPadding.bottom; + + if (self.actions.count > 0) { + if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) { + maximumHeight -= self.visualStyle.buttonHeight; + } else { + maximumHeight -= self.visualStyle.buttonHeight * [self.buttonCollectionView numberOfItemsInSection:0]; + } + } + + return maximumHeight; +} + - (void)layoutSubviews { [super layoutSubviews]; [self applyCurrentStyleToAlertElements]; - [self.visualEffectView sdc_pinSize:CGSizeMake(self.visualStyle.width, 120)]; + [self.visualEffectView sdc_pinWidth:self.visualStyle.width]; [self.visualEffectView.contentView addSubview:self.scrollView]; [self.scrollView setNeedsLayout]; [self.scrollView layoutIfNeeded]; - [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop|UIRectEdgeRight]; - [self.scrollView sdc_setMaximumHeight:76]; + [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop|UIRectEdgeRight insets:self.visualStyle.contentPadding]; + [self.scrollView sdc_setMaximumHeight:[self maximumHeightForScrollView]]; + self.scrollView.contentSize = CGSizeMake(self.visualStyle.width - self.visualStyle.contentPadding.left + self.visualStyle.contentPadding.right, [self.scrollView intrinsicContentSize].height); [self.visualEffectView.contentView addSubview:self.buttonCollectionView]; - [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView]; - [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeRight]; + [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView inset:self.visualStyle.contentPadding.top]; + [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]; [self.buttonCollectionView sdc_pinHeight:self.visualStyle.buttonHeight]; [self addSubview:self.visualEffectView]; diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index 0da6a506..5c966a72 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -60,9 +60,6 @@ - (void)setMessage:(NSString *)message { - (void)setVisualStyle:(id)visualStyle { _visualStyle = visualStyle; - self.contentInset = visualStyle.contentPadding; - self.scrollIndicatorInsets = visualStyle.contentPadding; - self.titleLabel.font = visualStyle.titleLabelFont; self.messageLabel.font = visualStyle.messageLabelFont; @@ -101,9 +98,9 @@ - (CGSize)intrinsicContentSize { CGFloat intrinsicHeight = 0; if (self.message.length > 0) { - intrinsicHeight = CGRectGetMaxY(self.messageLabel.frame) + self.contentInset.top + self.contentInset.bottom; + intrinsicHeight = CGRectGetMaxY(self.messageLabel.frame); } else if (self.title.length > 0) { - intrinsicHeight = CGRectGetMaxY(self.titleLabel.frame) + self.contentInset.top + self.contentInset.bottom; + intrinsicHeight = CGRectGetMaxY(self.titleLabel.frame); } return CGSizeMake(UIViewNoIntrinsicMetric, intrinsicHeight); From 536079ece49a2139e9e03586e20225b533de6c60 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 27 Sep 2014 23:28:34 -0700 Subject: [PATCH 21/76] Allow forcing horizontal or vertical button layout --- SDCAlertView/SDCViewController.m | 4 ++- SDCAlertView/Source/SDCAlertController.h | 8 +++++ SDCAlertView/Source/SDCAlertController.m | 2 ++ ...CAlertControllerCollectionViewFlowLayout.m | 9 ++---- .../Source/SDCAlertRepresentationView.h | 3 ++ .../Source/SDCAlertRepresentationView.m | 31 +++++++++++++++++-- 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 1119e328..fb85e8a0 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -32,11 +32,13 @@ - (void)presentNow { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { - SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"MessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessageMessage" preferredStyle:SDCAlertControllerStyleAlert]; + SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; + ac.buttonLayout = SDCAlertControllerButtonLayoutHorizontal; [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:nil]]; [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { NSLog(@"%@", action.title); }]]; + [ac addAction:[SDCAlertAction actionWithTitle:@"Third" style:SDCAlertActionStyleDefault handler:nil]]; [self presentViewController:ac animated:YES completion:nil]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 397d4909..347b98d3 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -18,6 +18,12 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerStyle) { SDCAlertControllerStyleAlert = UIAlertControllerStyleAlert }; +typedef NS_ENUM(NSInteger, SDCAlertControllerButtonLayout) { + SDCAlertControllerButtonLayoutAutomatic, + SDCAlertControllerButtonLayoutHorizontal, + SDCAlertControllerButtonLayoutVertical +}; + @interface SDCAlertAction : NSObject + (instancetype)actionWithTitle:(NSString *)title style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *action))handler; @@ -36,6 +42,8 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerStyle) { - (void)addAction:(SDCAlertAction *)action; @property (nonatomic, readonly) NSArray *actions; +@property (nonatomic) SDCAlertControllerButtonLayout buttonLayout; + - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler; @property (nonatomic, readonly) NSArray *textFields; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index ae5c5222..dea51ed1 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -48,6 +48,7 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref _textFieldConfigurationHandlers = [NSMutableArray array]; _visualStyle = [[SDCAlertControllerDefaultVisualStyle alloc] init]; + _buttonLayout = SDCAlertControllerButtonLayoutAutomatic; self.modalPresentationStyle = UIModalPresentationCustom; self.transitioningDelegate = [[SDCAlertTransitioningDelegate alloc] init]; @@ -65,6 +66,7 @@ - (void)viewDidLoad { self.alert.delegate = self; self.alert.visualStyle = self.visualStyle; self.alert.actions = self.actions; + self.alert.buttonLayout = self.buttonLayout; [self.view addSubview:self.alert]; [self.alert sdc_centerInSuperview]; diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m index 0eb2d256..dab73e1d 100644 --- a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m @@ -15,6 +15,7 @@ - (instancetype)init { if (self) { self.minimumInteritemSpacing = 0; + self.minimumLineSpacing = 0; } return self; @@ -27,12 +28,6 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { [attributes addObject:[self layoutAttributesForDecorationViewOfKind:@"separator" atIndexPath:itemAttributes.indexPath]]; }]; - UICollectionViewLayoutAttributes *topSeparatorAttributes = [UICollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:@"separator" - withIndexPath:nil]; - topSeparatorAttributes.frame = CGRectMake(CGRectGetMinX(rect), CGRectGetMinY(rect), CGRectGetWidth(rect), 0.5); - - [attributes addObject:topSeparatorAttributes]; - return attributes; } @@ -45,7 +40,7 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(N withIndexPath:indexPath]; UICollectionViewLayoutAttributes *itemAttributes = [self layoutAttributesForItemAtIndexPath:indexPath]; - attributes.frame = CGRectMake(CGRectGetMaxX(itemAttributes.frame) - 0.5, CGRectGetMinY(itemAttributes.frame), 0.5, CGRectGetHeight(itemAttributes.frame)); + attributes.frame = CGRectMake(CGRectGetMinX(itemAttributes.frame), CGRectGetMinY(itemAttributes.frame), CGRectGetWidth(itemAttributes.frame), 0.5); attributes.zIndex = itemAttributes.zIndex + 1; return attributes; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.h b/SDCAlertView/Source/SDCAlertRepresentationView.h index 9a82e57c..166f29a5 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.h +++ b/SDCAlertView/Source/SDCAlertRepresentationView.h @@ -8,6 +8,8 @@ @import UIKit; +#import "SDCAlertController.h" // SDCAlertControllerButtonLayout + @class SDCAlertRepresentationView; @class SDCAlertAction; @@ -25,6 +27,7 @@ @property (nonatomic, copy) NSString *message; @property (nonatomic, copy) NSArray *actions; +@property (nonatomic) SDCAlertControllerButtonLayout buttonLayout; @property (nonatomic, strong) id visualStyle; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 9b651f5f..0e79ac39 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -56,6 +56,18 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { return self; } +- (void)setButtonLayout:(SDCAlertControllerButtonLayout)buttonLayout { + _buttonLayout = buttonLayout; + + UICollectionViewScrollDirection direction = UICollectionViewScrollDirectionHorizontal; + + if (buttonLayout == SDCAlertControllerButtonLayoutVertical || (buttonLayout == SDCAlertControllerButtonLayoutAutomatic && self.actions.count == 2)) { + direction = UICollectionViewScrollDirectionVertical; + } + + self.collectionViewLayout.scrollDirection = direction; +} + - (CGFloat)maximumHeightForScrollView { CGFloat maximumHeight = CGRectGetHeight(self.superview.bounds) - self.visualStyle.margins.top - self.visualStyle.margins.bottom; maximumHeight -= self.visualStyle.contentPadding.top - self.visualStyle.contentPadding.bottom; @@ -71,6 +83,17 @@ - (CGFloat)maximumHeightForScrollView { return maximumHeight; } +- (CGFloat)heightForButtonCollectionView { + CGFloat horizontalLayoutHeight = self.visualStyle.buttonHeight; + CGFloat verticalLayoutHeight = self.visualStyle.buttonHeight * [self.buttonCollectionView numberOfItemsInSection:0]; + + switch (self.buttonLayout) { + case SDCAlertControllerButtonLayoutAutomatic: return (self.actions.count == 2) ? horizontalLayoutHeight : verticalLayoutHeight; + case SDCAlertControllerButtonLayoutHorizontal: return horizontalLayoutHeight; + case SDCAlertControllerButtonLayoutVertical: return verticalLayoutHeight; + } +} + - (void)layoutSubviews { [super layoutSubviews]; @@ -89,7 +112,7 @@ - (void)layoutSubviews { [self.visualEffectView.contentView addSubview:self.buttonCollectionView]; [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView inset:self.visualStyle.contentPadding.top]; [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]; - [self.buttonCollectionView sdc_pinHeight:self.visualStyle.buttonHeight]; + [self.buttonCollectionView sdc_pinHeight:[self heightForButtonCollectionView]]; [self addSubview:self.visualEffectView]; [self.visualEffectView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; @@ -133,7 +156,11 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { - return CGSizeMake(CGRectGetWidth(self.bounds) / self.actions.count, CGRectGetHeight(collectionView.bounds)); + if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionVertical) { + return CGSizeMake(CGRectGetWidth(self.bounds), self.visualStyle.buttonHeight); + } else { + return CGSizeMake(CGRectGetWidth(self.bounds) / self.actions.count, self.visualStyle.buttonHeight); + } } @end From 114ea7f70a5107fec99e814afd36e352a78e8973 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 27 Sep 2014 23:33:50 -0700 Subject: [PATCH 22/76] Enforce minimum button width for horizontal button layouts --- SDCAlertView/SDCViewController.m | 1 + SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m | 4 ++++ SDCAlertView/Source/SDCAlertControllerVisualStyle.h | 1 + SDCAlertView/Source/SDCAlertRepresentationView.m | 3 ++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index fb85e8a0..38929abf 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -39,6 +39,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath NSLog(@"%@", action.title); }]]; [ac addAction:[SDCAlertAction actionWithTitle:@"Third" style:SDCAlertActionStyleDefault handler:nil]]; + [ac addAction:[SDCAlertAction actionWithTitle:@"Fourth" style:SDCAlertActionStyleDefault handler:nil]]; [self presentViewController:ac animated:YES completion:nil]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index 89b3f754..f02f8352 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -20,6 +20,10 @@ - (CGFloat)buttonHeight { return 44; } +- (CGFloat)minimumButtonWidth { + return 90; // Fits exactly three buttons without scrolling +} + - (UIEdgeInsets)margins { return UIEdgeInsetsMake(3, 0, 3, 0); } diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index ec089882..2a535dd8 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -14,6 +14,7 @@ @property (nonatomic, readonly) CGFloat width; @property (nonatomic, readonly) CGFloat buttonHeight; +@property (nonatomic, readonly) CGFloat minimumButtonWidth; // For forced horizontal layout and 3+ buttons @property (nonatomic, readonly) UIEdgeInsets margins; @property (nonatomic, readonly) UIEdgeInsets contentPadding; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 0e79ac39..514cf9f3 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -159,7 +159,8 @@ - (CGSize)collectionView:(UICollectionView *)collectionView if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionVertical) { return CGSizeMake(CGRectGetWidth(self.bounds), self.visualStyle.buttonHeight); } else { - return CGSizeMake(CGRectGetWidth(self.bounds) / self.actions.count, self.visualStyle.buttonHeight); + CGFloat width = MAX(CGRectGetWidth(self.bounds) / self.actions.count, self.visualStyle.minimumButtonWidth); + return CGSizeMake(width, self.visualStyle.buttonHeight); } } From 4cbc7e50baac138a1b6928abd09e9df2deae6ef8 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 28 Sep 2014 00:29:28 -0700 Subject: [PATCH 23/76] Use custom layout attributes for separator styling --- SDCAlertView/SDCViewController.m | 1 - .../Source/SDCAlertCollectionViewCell.m | 11 +++-- ...CAlertControllerCollectionViewFlowLayout.h | 5 ++- ...CAlertControllerCollectionViewFlowLayout.m | 41 +++++++++++++++---- .../SDCAlertControllerDefaultVisualStyle.m | 8 ++++ .../Source/SDCAlertControllerVisualStyle.h | 3 +- .../Source/SDCAlertRepresentationView.m | 7 ++-- 7 files changed, 55 insertions(+), 21 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 38929abf..dbd6f1d3 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -33,7 +33,6 @@ - (void)presentNow { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; - ac.buttonLayout = SDCAlertControllerButtonLayoutHorizontal; [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:nil]]; [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { NSLog(@"%@", action.title); diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 83d2553d..a0b66889 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -61,14 +61,13 @@ - (void)setHighlighted:(BOOL)highlighted { @implementation SDCAlertControllerSeparatorView -- (instancetype)initWithFrame:(CGRect)frame { - self = [super initWithFrame:frame]; +- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes { + [super applyLayoutAttributes:layoutAttributes]; - if (self) { - self.backgroundColor = [UIColor grayColor]; + // By keeping this very generic, this class doesn't have to know about the class name of the custom layout attributes + if ([layoutAttributes respondsToSelector:@selector(backgroundColor)]) { + self.backgroundColor = [layoutAttributes performSelector:@selector(backgroundColor)]; } - - return self; } @end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h index 4c963be3..694ff790 100644 --- a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.h @@ -10,8 +10,9 @@ #import "SDCAlertControllerVisualStyle.h" -@interface SDCAlertControllerCollectionViewFlowLayout : UICollectionViewFlowLayout +extern NSString *const SDCAlertControllerDecorationKindHorizontalSeparator; +extern NSString *const SDCAlertControllerDecorationKindVerticalSeparator; +@interface SDCAlertControllerCollectionViewFlowLayout : UICollectionViewFlowLayout @property (nonatomic, strong) id visualStyle; - @end diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m index dab73e1d..aebe0e8b 100644 --- a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m @@ -8,8 +8,19 @@ #import "SDCAlertControllerCollectionViewFlowLayout.h" +NSString *const SDCAlertControllerDecorationKindHorizontalSeparator = @"SDCAlertControllerDecorationKindHorizontalSeparator"; +NSString *const SDCAlertControllerDecorationKindVerticalSeparator = @"SDCAlertControllerDecorationKindVerticalSeparator"; + +@interface SDCAlertControllerCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes +@property (nonatomic, strong) UIColor *backgroundColor; +@end + @implementation SDCAlertControllerCollectionViewFlowLayout ++ (Class)layoutAttributesClass { + return [SDCAlertControllerCollectionViewLayoutAttributes class]; +} + - (instancetype)init { self = [super init]; @@ -25,25 +36,39 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSMutableArray *attributes = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; [[attributes copy] enumerateObjectsUsingBlock:^(UICollectionViewLayoutAttributes *itemAttributes, NSUInteger idx, BOOL *stop) { - [attributes addObject:[self layoutAttributesForDecorationViewOfKind:@"separator" atIndexPath:itemAttributes.indexPath]]; + NSIndexPath *indexPath = itemAttributes.indexPath; + + [attributes addObject:[self layoutAttributesForDecorationViewOfKind:SDCAlertControllerDecorationKindHorizontalSeparator atIndexPath:indexPath]]; + + if (self.scrollDirection == UICollectionViewScrollDirectionHorizontal && indexPath.item > 0) { + [attributes addObject:[self layoutAttributesForDecorationViewOfKind:SDCAlertControllerDecorationKindVerticalSeparator atIndexPath:indexPath]]; + } }]; return attributes; } -- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { - return [super layoutAttributesForItemAtIndexPath:indexPath]; -} - - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { - UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:elementKind - withIndexPath:indexPath]; + SDCAlertControllerCollectionViewLayoutAttributes *attributes = [SDCAlertControllerCollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:elementKind + withIndexPath:indexPath]; UICollectionViewLayoutAttributes *itemAttributes = [self layoutAttributesForItemAtIndexPath:indexPath]; - attributes.frame = CGRectMake(CGRectGetMinX(itemAttributes.frame), CGRectGetMinY(itemAttributes.frame), CGRectGetWidth(itemAttributes.frame), 0.5); attributes.zIndex = itemAttributes.zIndex + 1; + attributes.backgroundColor = self.visualStyle.buttonSeparatorColor; + + CGRect decorationFrame = itemAttributes.frame; + if (elementKind == SDCAlertControllerDecorationKindHorizontalSeparator) { + decorationFrame.size.height = self.visualStyle.buttonSeparatorThickness; + } else { + decorationFrame.size.width = self.visualStyle.buttonSeparatorThickness; + } + + attributes.frame = decorationFrame; return attributes; } +@end + +@implementation SDCAlertControllerCollectionViewLayoutAttributes @end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index f02f8352..aaa05dbb 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -42,6 +42,14 @@ - (UIView *)buttonHighlightBackgroundView { return view; } +- (UIColor *)buttonSeparatorColor { + return [UIColor colorWithWhite:0.5 alpha:0.5]; +} + +- (CGFloat)buttonSeparatorThickness { + return 1 / [UIScreen mainScreen].scale; +} + - (UIFont *)titleLabelFont { return [UIFont boldSystemFontOfSize:17]; } diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index 2a535dd8..d0327e02 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -20,8 +20,9 @@ @property (nonatomic, readonly) UIEdgeInsets contentPadding; @property (nonatomic, readonly) CGFloat labelSpacing; - @property (nonatomic, readonly) UIView *buttonHighlightBackgroundView; +@property (nonatomic, readonly) UIColor *buttonSeparatorColor; +@property (nonatomic, readonly) CGFloat buttonSeparatorThickness; @property (nonatomic, readonly) UIFont *titleLabelFont; @property (nonatomic, readonly) UIFont *messageLabelFont; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 514cf9f3..ddfaf7e5 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -40,11 +40,12 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { _scrollView = [[SDCAlertScrollView alloc] initWithTitle:title message:message]; _collectionViewLayout = [[SDCAlertControllerCollectionViewFlowLayout alloc] init]; + [_collectionViewLayout registerClass:[SDCAlertControllerSeparatorView class] forDecorationViewOfKind:SDCAlertControllerDecorationKindHorizontalSeparator]; + [_collectionViewLayout registerClass:[SDCAlertControllerSeparatorView class] forDecorationViewOfKind:SDCAlertControllerDecorationKindVerticalSeparator]; + _buttonCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_collectionViewLayout]; [_buttonCollectionView setTranslatesAutoresizingMaskIntoConstraints:NO]; - [_buttonCollectionView registerClass:[SDCAlertCollectionViewCell class] forCellWithReuseIdentifier:SDCAlertControllerCellReuseIdentifier]; - [_buttonCollectionView.collectionViewLayout registerClass:[SDCAlertControllerSeparatorView class] forDecorationViewOfKind:@"separator"]; _buttonCollectionView.delegate = self; _buttonCollectionView.dataSource = self; @@ -61,7 +62,7 @@ - (void)setButtonLayout:(SDCAlertControllerButtonLayout)buttonLayout { UICollectionViewScrollDirection direction = UICollectionViewScrollDirectionHorizontal; - if (buttonLayout == SDCAlertControllerButtonLayoutVertical || (buttonLayout == SDCAlertControllerButtonLayoutAutomatic && self.actions.count == 2)) { + if (buttonLayout == SDCAlertControllerButtonLayoutVertical || (buttonLayout == SDCAlertControllerButtonLayoutAutomatic && self.actions.count != 2)) { direction = UICollectionViewScrollDirectionVertical; } From 41dbeb16882ae97a4d25014223b535028e5889f1 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 28 Sep 2014 00:31:58 -0700 Subject: [PATCH 24/76] Adjust tint for modality awareness --- SDCAlertView/Source/SDCAlertPresentationController.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SDCAlertView/Source/SDCAlertPresentationController.m b/SDCAlertView/Source/SDCAlertPresentationController.m index 2a53d6e9..550b4491 100644 --- a/SDCAlertView/Source/SDCAlertPresentationController.m +++ b/SDCAlertView/Source/SDCAlertPresentationController.m @@ -28,6 +28,8 @@ - (instancetype)initWithPresentedViewController:(UIViewController *)presentedVie - (void)presentationTransitionWillBegin { [super presentationTransitionWillBegin]; + self.presentingViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed; + self.dimmingView.alpha = 0; [[self containerView] addSubview:self.dimmingView]; @@ -39,6 +41,8 @@ - (void)presentationTransitionWillBegin { - (void)dismissalTransitionWillBegin { [super dismissalTransitionWillBegin]; + self.presentingViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic; + [self.presentedViewController.transitionCoordinator animateAlongsideTransition:^(id context) { self.dimmingView.alpha = 0; } completion:nil]; From 022217d4038c52274881e358a018a7a68139862a Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 28 Sep 2014 14:25:34 -0700 Subject: [PATCH 25/76] Use view controller containment for displaying text fields --- SDCAlertView.xcodeproj/project.pbxproj | 12 ++++++ SDCAlertView/SDCViewController.m | 6 ++- SDCAlertView/Source/SDCAlertController.m | 43 ++++++++++++++----- .../Source/SDCAlertRepresentationView.h | 3 ++ .../Source/SDCAlertRepresentationView.m | 4 ++ SDCAlertView/Source/SDCAlertScrollView.h | 5 +++ SDCAlertView/Source/SDCAlertScrollView.m | 8 ++++ .../Source/SDCAlertTextFieldTableViewCell.h | 15 +++++++ .../Source/SDCAlertTextFieldTableViewCell.m | 21 +++++++++ .../Source/SDCAlertTextFieldViewController.h | 15 +++++++ .../Source/SDCAlertTextFieldViewController.m | 34 +++++++++++++++ 11 files changed, 154 insertions(+), 12 deletions(-) create mode 100644 SDCAlertView/Source/SDCAlertTextFieldTableViewCell.h create mode 100644 SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m create mode 100644 SDCAlertView/Source/SDCAlertTextFieldViewController.h create mode 100644 SDCAlertView/Source/SDCAlertTextFieldViewController.m diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index f7e93ee2..b4c43238 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -37,8 +37,10 @@ D2A520181840176300837A1A /* SDCAlertView.podspec in Resources */ = {isa = PBXBuildFile; fileRef = D2A520171840176300837A1A /* SDCAlertView.podspec */; }; D2A5E0D119D3D6A90034B709 /* SDCAlertCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */; }; D2A6A0DB19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */; }; + D2A6F1C519D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */; }; D2BD0CC418FEB2C400520E33 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC318FEB2C400520E33 /* iPad.storyboard */; }; D2BD0CC618FED65700520E33 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC518FED65700520E33 /* CHANGELOG.md */; }; + D2D5A77019D8A64B00386078 /* SDCAlertTextFieldViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */; }; D2F8345918EF2893000BB281 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = D2F8345718EF2887000BB281 /* Podfile */; }; D2F9D2BD18400CD300F85B10 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = D2F9D2BC18400CD200F85B10 /* README.md */; }; D2F9D2BF18400DAF00F85B10 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = D2F9D2BE18400DAF00F85B10 /* LICENSE */; }; @@ -109,8 +111,12 @@ D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertCollectionViewCell.m; sourceTree = ""; }; D2A6A0D919D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerCollectionViewFlowLayout.h; sourceTree = ""; }; D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerCollectionViewFlowLayout.m; sourceTree = ""; }; + D2A6F1C319D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertTextFieldTableViewCell.h; sourceTree = ""; }; + D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertTextFieldTableViewCell.m; sourceTree = ""; }; D2BD0CC318FEB2C400520E33 /* iPad.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = iPad.storyboard; sourceTree = ""; }; D2BD0CC518FED65700520E33 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CHANGELOG.md; sourceTree = ""; }; + D2D5A76E19D8A64B00386078 /* SDCAlertTextFieldViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertTextFieldViewController.h; sourceTree = ""; }; + D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertTextFieldViewController.m; sourceTree = ""; }; D2F8345718EF2887000BB281 /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = ""; }; D2F9D2BC18400CD200F85B10 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = ""; }; D2F9D2BE18400DAF00F85B10 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; @@ -251,6 +257,10 @@ D26506EF19C61B8000BF34B9 /* 2.0 */ = { isa = PBXGroup; children = ( + D2D5A76E19D8A64B00386078 /* SDCAlertTextFieldViewController.h */, + D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */, + D2A6F1C319D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.h */, + D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */, D2988E0519D7960900140116 /* SDCAlertControllerVisualStyle.h */, D2666A3E19CFDE2800167157 /* SDCAlertRepresentationView.h */, D2666A3F19CFDE2800167157 /* SDCAlertRepresentationView.m */, @@ -456,8 +466,10 @@ buildActionMask = 2147483647; files = ( D2A5E0D119D3D6A90034B709 /* SDCAlertCollectionViewCell.m in Sources */, + D2A6F1C519D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m in Sources */, D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */, D25B3CB417ECE7A6004B32A2 /* main.m in Sources */, + D2D5A77019D8A64B00386078 /* SDCAlertTextFieldViewController.m in Sources */, D259FC1519CEB0EB00BA6B36 /* SDCAlertTransition.m in Sources */, D2988E0319D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m in Sources */, D259FC1219CEB02100BA6B36 /* SDCAlertPresentationController.m in Sources */, diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index dbd6f1d3..8bfc7d21 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -27,6 +27,9 @@ - (void)presentNow { UIAlertController *b = [UIAlertController alertControllerWithTitle:@"Title 2" message:@"Message 2" preferredStyle:UIAlertControllerStyleAlert]; [b addAction:[UIAlertAction actionWithTitle:@"Button 2" style:UIAlertActionStyleDefault handler:nil]]; [b addAction:[UIAlertAction actionWithTitle:@"Button 33??" style:UIAlertActionStyleCancel handler:nil]]; + + [b addTextFieldWithConfigurationHandler:nil]; + [self presentViewController:b animated:YES completion:nil]; } @@ -37,8 +40,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { NSLog(@"%@", action.title); }]]; - [ac addAction:[SDCAlertAction actionWithTitle:@"Third" style:SDCAlertActionStyleDefault handler:nil]]; - [ac addAction:[SDCAlertAction actionWithTitle:@"Fourth" style:SDCAlertActionStyleDefault handler:nil]]; + [ac addTextFieldWithConfigurationHandler:nil]; [self presentViewController:ac animated:YES completion:nil]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index dea51ed1..3caebc98 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -8,6 +8,7 @@ #import "SDCAlertController.h" +#import "SDCAlertTextFieldViewController.h" #import "SDCAlertTransition.h" #import "SDCAlertRepresentationView.h" #import "SDCAlertControllerDefaultVisualStyle.h" @@ -20,7 +21,7 @@ @interface SDCAlertAction (Private) @interface SDCAlertController () @property (nonatomic, strong) NSMutableArray *mutableActions; -@property (nonatomic, strong) NSMutableArray *textFieldConfigurationHandlers; +@property (nonatomic, strong) NSMutableArray *mutableTextFields; @property (nonatomic, strong) id transitioningDelegate; @property (nonatomic, strong) id visualStyle; @property (nonatomic, strong) SDCAlertRepresentationView *alert; @@ -45,7 +46,7 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref _message = message; _mutableActions = [NSMutableArray array]; - _textFieldConfigurationHandlers = [NSMutableArray array]; + _mutableTextFields = [NSMutableArray array]; _visualStyle = [[SDCAlertControllerDefaultVisualStyle alloc] init]; _buttonLayout = SDCAlertControllerButtonLayoutAutomatic; @@ -62,16 +63,33 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref - (void)viewDidLoad { [super viewDidLoad]; - self.alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; - self.alert.delegate = self; - self.alert.visualStyle = self.visualStyle; - self.alert.actions = self.actions; - self.alert.buttonLayout = self.buttonLayout; + self.alert = [self createAlertView]; [self.view addSubview:self.alert]; [self.alert sdc_centerInSuperview]; +} + +- (void)showTextFieldsInAlertView:(SDCAlertRepresentationView *)alertView { + if (self.textFields.count > 0) { + SDCAlertTextFieldViewController *textFieldViewController = [[SDCAlertTextFieldViewController alloc] init]; + textFieldViewController.textFields = self.textFields; + + [self addChildViewController:textFieldViewController]; + [alertView showTextFieldViewController:textFieldViewController]; + [textFieldViewController didMoveToParentViewController:self]; + } +} + +- (SDCAlertRepresentationView *)createAlertView { + SDCAlertRepresentationView *alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; + alert.delegate = self; + alert.visualStyle = self.visualStyle; + alert.actions = self.actions; + alert.buttonLayout = self.buttonLayout; - [self.view addSubview:self.alert]; + [self showTextFieldsInAlertView:alert]; + + return alert; } #pragma mark - Style @@ -109,11 +127,16 @@ - (void)alertRepresentationView:(SDCAlertRepresentationView *)sender didPerformA #pragma mark - Alert Text Fields - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *))configurationHandler { - [self.textFieldConfigurationHandlers addObject:[configurationHandler copy]]; + UITextField *textField = [[UITextField alloc] init]; + [self.mutableTextFields addObject:textField]; + + if (configurationHandler) { + configurationHandler(textField); + } } - (NSArray *)textFields { - return [NSArray array]; + return [self.mutableTextFields copy]; } @end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.h b/SDCAlertView/Source/SDCAlertRepresentationView.h index 166f29a5..02f2b573 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.h +++ b/SDCAlertView/Source/SDCAlertRepresentationView.h @@ -12,6 +12,7 @@ @class SDCAlertRepresentationView; @class SDCAlertAction; +@class SDCAlertTextFieldViewController; @protocol SDCAlertRepresentationViewDelegate - (void)alertRepresentationView:(SDCAlertRepresentationView *)sender didPerformAction:(SDCAlertAction *)action; @@ -33,4 +34,6 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; +- (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController; + @end diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index ddfaf7e5..1457e1cc 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -69,6 +69,10 @@ - (void)setButtonLayout:(SDCAlertControllerButtonLayout)buttonLayout { self.collectionViewLayout.scrollDirection = direction; } +- (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController { + self.scrollView.textFieldViewController = viewController; +} + - (CGFloat)maximumHeightForScrollView { CGFloat maximumHeight = CGRectGetHeight(self.superview.bounds) - self.visualStyle.margins.top - self.visualStyle.margins.bottom; maximumHeight -= self.visualStyle.contentPadding.top - self.visualStyle.contentPadding.bottom; diff --git a/SDCAlertView/Source/SDCAlertScrollView.h b/SDCAlertView/Source/SDCAlertScrollView.h index a5c6cfd4..3e68b0cc 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.h +++ b/SDCAlertView/Source/SDCAlertScrollView.h @@ -10,10 +10,15 @@ #import "SDCAlertControllerVisualStyle.h" +@class SDCAlertTextFieldViewController; + @interface SDCAlertScrollView : UIScrollView +@property (nonatomic, strong) SDCAlertTextFieldViewController *textFieldViewController; @property (nonatomic, strong) id visualStyle; - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; +- (void)addTextFields:(NSArray *)textFields; + @end diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index 5c966a72..eaec2b47 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -7,7 +7,10 @@ // #import "SDCAlertScrollView.h" + +#import "SDCAlertTextFieldViewController.h" #import "SDCAlertLabel.h" + #import "UIView+SDCAutoLayout.h" @interface SDCAlertScrollView () @@ -66,6 +69,11 @@ - (void)setVisualStyle:(id)visualStyle { [self setNeedsLayout]; } +- (void)setTextFieldViewController:(SDCAlertTextFieldViewController *)textFieldViewController { + [self addSubview:textFieldViewController.view]; + [textFieldViewController.view sdc_alignEdgesWithSuperview:UIRectEdgeAll]; +} + - (void)layoutSubviews { [super layoutSubviews]; diff --git a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.h b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.h new file mode 100644 index 00000000..6a155625 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.h @@ -0,0 +1,15 @@ +// +// SDCAlertTextFieldTableViewCell.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/28/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +@import UIKit; + +@interface SDCAlertTextFieldTableViewCell : UITableViewCell + +@property (nonatomic, strong) UITextField *textField; + +@end diff --git a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m new file mode 100644 index 00000000..98f3d81d --- /dev/null +++ b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m @@ -0,0 +1,21 @@ +// +// SDCAlertTextFieldTableViewCell.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/28/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertTextFieldTableViewCell.h" + +#import "UIView+SDCAutoLayout.h" + +@implementation SDCAlertTextFieldTableViewCell + +- (void)setTextField:(UITextField *)textField { + _textField = textField; + + [textField sdc_alignEdgesWithSuperview:UIRectEdgeAll]; +} + +@end diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.h b/SDCAlertView/Source/SDCAlertTextFieldViewController.h new file mode 100644 index 00000000..96de4e33 --- /dev/null +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.h @@ -0,0 +1,15 @@ +// +// SDCAlertTextFieldViewController.h +// SDCAlertView +// +// Created by Scott Berrevoets on 9/28/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +@import UIKit; + +@interface SDCAlertTextFieldViewController : UITableViewController + +@property (nonatomic, strong) NSArray *textFields; + +@end diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.m b/SDCAlertView/Source/SDCAlertTextFieldViewController.m new file mode 100644 index 00000000..555526fe --- /dev/null +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.m @@ -0,0 +1,34 @@ +// +// SDCAlertTextFieldViewController.m +// SDCAlertView +// +// Created by Scott Berrevoets on 9/28/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCAlertTextFieldViewController.h" + +#import "SDCAlertTextFieldTableViewCell.h" + +static NSString *const SDCAlertTextFieldCellIdentifier = @"SDCAlertTextFieldCellIdentifier"; + +@implementation SDCAlertTextFieldViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + [self.tableView registerClass:[SDCAlertTextFieldTableViewCell class] forCellReuseIdentifier:SDCAlertTextFieldCellIdentifier]; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return self.textFields.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + SDCAlertTextFieldTableViewCell *textFieldCell = [tableView dequeueReusableCellWithIdentifier:SDCAlertTextFieldCellIdentifier + forIndexPath:indexPath]; + + textFieldCell.textField = self.textFields[indexPath.row]; + return textFieldCell; +} + +@end From d1bc13abcfa145a14d7fbe3776318473d9852732 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 1 Oct 2014 22:57:25 -0700 Subject: [PATCH 26/76] Show added text fields in alert --- SDCAlertView/SDCViewController.m | 6 +- .../SDCAlertControllerDefaultVisualStyle.m | 8 ++- .../Source/SDCAlertControllerVisualStyle.h | 1 + .../Source/SDCAlertRepresentationView.m | 7 +-- SDCAlertView/Source/SDCAlertScrollView.h | 2 - SDCAlertView/Source/SDCAlertScrollView.m | 58 ++++++------------- .../Source/SDCAlertTextFieldTableViewCell.m | 3 + .../Source/SDCAlertTextFieldViewController.m | 6 ++ 8 files changed, 42 insertions(+), 49 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 8bfc7d21..55651e12 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -24,13 +24,15 @@ @implementation SDCViewController - (void)presentNow { - UIAlertController *b = [UIAlertController alertControllerWithTitle:@"Title 2" message:@"Message 2" preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *b = [UIAlertController alertControllerWithTitle:@"G" message:@"Hello" preferredStyle:UIAlertControllerStyleAlert]; [b addAction:[UIAlertAction actionWithTitle:@"Button 2" style:UIAlertActionStyleDefault handler:nil]]; [b addAction:[UIAlertAction actionWithTitle:@"Button 33??" style:UIAlertActionStyleCancel handler:nil]]; [b addTextFieldWithConfigurationHandler:nil]; - [self presentViewController:b animated:YES completion:nil]; + [self presentViewController:b animated:YES completion:^{ +// b.title = nil; + }]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index aaa05dbb..eff25fbc 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -29,11 +29,15 @@ - (UIEdgeInsets)margins { } - (UIEdgeInsets)contentPadding { - return UIEdgeInsetsMake(19, 15, 18.5, 15); + return UIEdgeInsetsMake(36, 16, 12, 16); } - (CGFloat)labelSpacing { - return 4; + return 24; +} + +- (CGFloat)textFieldsTopSpacing { + return 24; } - (UIView *)buttonHighlightBackgroundView { diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index d0327e02..c9495f0c 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -19,6 +19,7 @@ @property (nonatomic, readonly) UIEdgeInsets margins; @property (nonatomic, readonly) UIEdgeInsets contentPadding; @property (nonatomic, readonly) CGFloat labelSpacing; +@property (nonatomic, readonly) CGFloat textFieldsTopSpacing; @property (nonatomic, readonly) UIView *buttonHighlightBackgroundView; @property (nonatomic, readonly) UIColor *buttonSeparatorColor; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 1457e1cc..25e318de 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -75,7 +75,6 @@ - (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewContr - (CGFloat)maximumHeightForScrollView { CGFloat maximumHeight = CGRectGetHeight(self.superview.bounds) - self.visualStyle.margins.top - self.visualStyle.margins.bottom; - maximumHeight -= self.visualStyle.contentPadding.top - self.visualStyle.contentPadding.bottom; if (self.actions.count > 0) { if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) { @@ -110,12 +109,12 @@ - (void)layoutSubviews { [self.scrollView setNeedsLayout]; [self.scrollView layoutIfNeeded]; - [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop|UIRectEdgeRight insets:self.visualStyle.contentPadding]; + [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop|UIRectEdgeRight]; [self.scrollView sdc_setMaximumHeight:[self maximumHeightForScrollView]]; - self.scrollView.contentSize = CGSizeMake(self.visualStyle.width - self.visualStyle.contentPadding.left + self.visualStyle.contentPadding.right, [self.scrollView intrinsicContentSize].height); + self.scrollView.contentSize = CGSizeMake(self.visualStyle.width, [self.scrollView intrinsicContentSize].height); [self.visualEffectView.contentView addSubview:self.buttonCollectionView]; - [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView inset:self.visualStyle.contentPadding.top]; + [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView]; [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]; [self.buttonCollectionView sdc_pinHeight:[self heightForButtonCollectionView]]; diff --git a/SDCAlertView/Source/SDCAlertScrollView.h b/SDCAlertView/Source/SDCAlertScrollView.h index 3e68b0cc..2b9eaaf9 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.h +++ b/SDCAlertView/Source/SDCAlertScrollView.h @@ -19,6 +19,4 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; -- (void)addTextFields:(NSArray *)textFields; - @end diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index eaec2b47..bd2ad603 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -27,7 +27,10 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { if (self) { _titleLabel = [[SDCAlertLabel alloc] init]; + [self addSubview:_titleLabel]; + _messageLabel = [[SDCAlertLabel alloc] init]; + [self addSubview:_messageLabel]; self.title = title; self.message = message; @@ -39,25 +42,13 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { } - (void)setTitle:(NSString *)title { - BOOL requiresViewHierarchyUpdate = (_title && !title) || (!_title && title); - _title = title; _titleLabel.text = title; - - if (requiresViewHierarchyUpdate && self.superview) { - [self setNeedsLayout]; - } } - (void)setMessage:(NSString *)message { - BOOL requiresViewHierarchyUpdate = (_message && !message) || (!_message && message); - _message = message; _messageLabel.text = message; - - if (requiresViewHierarchyUpdate && self.superview) { - [self setNeedsLayout]; - } } - (void)setVisualStyle:(id)visualStyle { @@ -70,46 +61,35 @@ - (void)setVisualStyle:(id)visualStyle { } - (void)setTextFieldViewController:(SDCAlertTextFieldViewController *)textFieldViewController { + _textFieldViewController = textFieldViewController; + + [textFieldViewController.view setTranslatesAutoresizingMaskIntoConstraints:NO]; [self addSubview:textFieldViewController.view]; - [textFieldViewController.view sdc_alignEdgesWithSuperview:UIRectEdgeAll]; } - (void)layoutSubviews { [super layoutSubviews]; - if (self.title.length > 0) { - [self addSubview:self.titleLabel]; - [self.titleLabel sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop]; - [self.titleLabel sdc_pinWidthToWidthOfView:self offset:-(self.visualStyle.contentPadding.left + self.visualStyle.contentPadding.right)]; - } else { - [self.titleLabel removeFromSuperview]; - } + [self.titleLabel sdc_alignEdgesWithSuperview:UIRectEdgeLeft insets:self.visualStyle.contentPadding]; + [self.titleLabel sdc_pinWidthToWidthOfView:self offset:-(self.visualStyle.contentPadding.left + self.visualStyle.contentPadding.right)]; - if (self.message.length > 0) { - [self addSubview:self.messageLabel]; - [self.messageLabel sdc_alignEdgesWithSuperview:UIRectEdgeLeft]; - [self.messageLabel sdc_pinWidthToWidthOfView:self offset:-(self.visualStyle.contentPadding.left + self.visualStyle.contentPadding.right)]; - - if (self.title.length > 0) { - [self.messageLabel sdc_pinVerticalSpacing:self.visualStyle.labelSpacing toView:self.titleLabel]; - } else { - [self.messageLabel sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeTop ofView:self inset:self.visualStyle.labelSpacing]; - } - } else { - [self.messageLabel removeFromSuperview]; + [self.messageLabel sdc_alignEdges:UIRectEdgeLeft|UIRectEdgeRight withView:self.titleLabel]; + + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeFirstBaseline relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:self.visualStyle.contentPadding.top]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeLastBaseline relatedBy:NSLayoutRelationEqual toItem:self.titleLabel attribute:NSLayoutAttributeFirstBaseline multiplier:1 constant:self.visualStyle.labelSpacing]]; + + if (self.textFieldViewController) { + [self.textFieldViewController.view sdc_alignEdges:UIRectEdgeLeft|UIRectEdgeRight withView:self.titleLabel]; + [self.textFieldViewController.view sdc_pinHeight:25 + self.visualStyle.contentPadding.bottom]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.textFieldViewController.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeLastBaseline multiplier:1 constant:self.visualStyle.textFieldsTopSpacing]]; } [self invalidateIntrinsicContentSize]; } - (CGSize)intrinsicContentSize { - CGFloat intrinsicHeight = 0; - - if (self.message.length > 0) { - intrinsicHeight = CGRectGetMaxY(self.messageLabel.frame); - } else if (self.title.length > 0) { - intrinsicHeight = CGRectGetMaxY(self.titleLabel.frame); - } + UIView *lastView = (self.textFieldViewController) ? self.textFieldViewController.view : self.messageLabel; + CGFloat intrinsicHeight = CGRectGetMaxY(lastView.frame); return CGSizeMake(UIViewNoIntrinsicMetric, intrinsicHeight); } diff --git a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m index 98f3d81d..b89a9514 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m +++ b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m @@ -15,6 +15,9 @@ @implementation SDCAlertTextFieldTableViewCell - (void)setTextField:(UITextField *)textField { _textField = textField; + [textField setTranslatesAutoresizingMaskIntoConstraints:NO]; + + [self.contentView addSubview:textField]; [textField sdc_alignEdgesWithSuperview:UIRectEdgeAll]; } diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.m b/SDCAlertView/Source/SDCAlertTextFieldViewController.m index 555526fe..0eed74e7 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.m +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.m @@ -17,6 +17,12 @@ @implementation SDCAlertTextFieldViewController - (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerClass:[SDCAlertTextFieldTableViewCell class] forCellReuseIdentifier:SDCAlertTextFieldCellIdentifier]; + + UITextField *dummyTextField = [[UITextField alloc] init]; + self.tableView.rowHeight = [dummyTextField intrinsicContentSize].height; + self.tableView.scrollEnabled = NO; + self.tableView.separatorColor = [UIColor clearColor]; + self.tableView.backgroundColor = [UIColor clearColor]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { From a5ab7cb18adcfc0580d6193dbc211c8ad1759b4d Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 1 Oct 2014 23:49:31 -0700 Subject: [PATCH 27/76] Properly lay out and stylize text fields --- SDCAlertView/SDCViewController.m | 5 ++- SDCAlertView/Source/SDCAlertController.m | 1 + .../SDCAlertControllerDefaultVisualStyle.m | 8 +++-- .../Source/SDCAlertControllerVisualStyle.h | 1 + SDCAlertView/Source/SDCAlertScrollView.m | 31 ++++++++++++++++--- .../Source/SDCAlertTextFieldTableViewCell.m | 21 +++++++++++-- .../Source/SDCAlertTextFieldViewController.h | 2 ++ .../Source/SDCAlertTextFieldViewController.m | 14 ++++++--- 8 files changed, 69 insertions(+), 14 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 55651e12..c78c8c73 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -24,11 +24,12 @@ @implementation SDCViewController - (void)presentNow { - UIAlertController *b = [UIAlertController alertControllerWithTitle:@"G" message:@"Hello" preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *b = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert]; [b addAction:[UIAlertAction actionWithTitle:@"Button 2" style:UIAlertActionStyleDefault handler:nil]]; [b addAction:[UIAlertAction actionWithTitle:@"Button 33??" style:UIAlertActionStyleCancel handler:nil]]; [b addTextFieldWithConfigurationHandler:nil]; + [b addTextFieldWithConfigurationHandler:nil]; [self presentViewController:b animated:YES completion:^{ // b.title = nil; @@ -43,6 +44,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath NSLog(@"%@", action.title); }]]; [ac addTextFieldWithConfigurationHandler:nil]; + [ac addTextFieldWithConfigurationHandler:nil]; + [self presentViewController:ac animated:YES completion:nil]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 3caebc98..cf5ff331 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -128,6 +128,7 @@ - (void)alertRepresentationView:(SDCAlertRepresentationView *)sender didPerformA - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *))configurationHandler { UITextField *textField = [[UITextField alloc] init]; + textField.font = self.visualStyle.textFieldFont; [self.mutableTextFields addObject:textField]; if (configurationHandler) { diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index eff25fbc..fdd27e83 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -33,7 +33,7 @@ - (UIEdgeInsets)contentPadding { } - (CGFloat)labelSpacing { - return 24; + return 18; } - (CGFloat)textFieldsTopSpacing { @@ -59,7 +59,11 @@ - (UIFont *)titleLabelFont { } - (UIFont *)messageLabelFont { - return [UIFont systemFontOfSize:14]; + return [UIFont systemFontOfSize:13]; +} + +- (UIFont *)textFieldFont { + return [UIFont systemFontOfSize:13]; } - (UIColor *)textColorForButtonRepresentingAction:(SDCAlertAction *)action { diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index c9495f0c..da347b6f 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -27,6 +27,7 @@ @property (nonatomic, readonly) UIFont *titleLabelFont; @property (nonatomic, readonly) UIFont *messageLabelFont; +@property (nonatomic, readonly) UIFont *textFieldFont; - (UIColor *)textColorForButtonRepresentingAction:(SDCAlertAction *)action; - (UIFont *)fontForButtonRepresentingAction:(SDCAlertAction *)action; diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index bd2ad603..d88e64f9 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -75,13 +75,36 @@ - (void)layoutSubviews { [self.messageLabel sdc_alignEdges:UIRectEdgeLeft|UIRectEdgeRight withView:self.titleLabel]; - [self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleLabel attribute:NSLayoutAttributeFirstBaseline relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:self.visualStyle.contentPadding.top]]; - [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel attribute:NSLayoutAttributeLastBaseline relatedBy:NSLayoutRelationEqual toItem:self.titleLabel attribute:NSLayoutAttributeFirstBaseline multiplier:1 constant:self.visualStyle.labelSpacing]]; + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleLabel + attribute:NSLayoutAttributeFirstBaseline + relatedBy:NSLayoutRelationEqual + toItem:self + attribute:NSLayoutAttributeTop + multiplier:1 + constant:self.visualStyle.contentPadding.top]]; + + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.messageLabel + attribute:NSLayoutAttributeFirstBaseline + relatedBy:NSLayoutRelationEqual + toItem:self.titleLabel + attribute:NSLayoutAttributeLastBaseline + multiplier:1 + constant:self.visualStyle.labelSpacing]]; if (self.textFieldViewController) { [self.textFieldViewController.view sdc_alignEdges:UIRectEdgeLeft|UIRectEdgeRight withView:self.titleLabel]; - [self.textFieldViewController.view sdc_pinHeight:25 + self.visualStyle.contentPadding.bottom]; - [self addConstraint:[NSLayoutConstraint constraintWithItem:self.textFieldViewController.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.messageLabel attribute:NSLayoutAttributeLastBaseline multiplier:1 constant:self.visualStyle.textFieldsTopSpacing]]; + + // Could use self.textFieldViewController.tableView to calculate height, but it being a UITableViewController subclass is an implementation detail. + CGFloat height = [self.textFieldViewController requiredHeightForDisplayingAllTextFields] + self.visualStyle.contentPadding.bottom; + [self.textFieldViewController.view sdc_pinHeight:height]; + + [self addConstraint:[NSLayoutConstraint constraintWithItem:self.textFieldViewController.view + attribute:NSLayoutAttributeTop + relatedBy:NSLayoutRelationEqual + toItem:self.messageLabel + attribute:NSLayoutAttributeLastBaseline + multiplier:1 + constant:self.visualStyle.textFieldsTopSpacing]]; } [self invalidateIntrinsicContentSize]; diff --git a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m index b89a9514..d282c0de 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m +++ b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m @@ -14,11 +14,26 @@ @implementation SDCAlertTextFieldTableViewCell - (void)setTextField:(UITextField *)textField { _textField = textField; - [textField setTranslatesAutoresizingMaskIntoConstraints:NO]; - [self.contentView addSubview:textField]; - [textField sdc_alignEdgesWithSuperview:UIRectEdgeAll]; + UIView *borderView = [[UIView alloc] init]; + [borderView setTranslatesAutoresizingMaskIntoConstraints:NO]; + borderView.backgroundColor = [UIColor colorWithRed:64.f/255 green:64.f/255 blue:64.f/255 alpha:1]; + + [self.contentView addSubview:borderView]; + [borderView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; + + UIView *textFieldView = [[UIView alloc] init]; + textFieldView.backgroundColor = [UIColor whiteColor]; + [textFieldView setTranslatesAutoresizingMaskIntoConstraints:NO]; + + [borderView addSubview:textFieldView]; + [textFieldView sdc_alignEdgesWithSuperview:UIRectEdgeAll insets:UIEdgeInsetsMake(0.5, 0.5, -0.5, -0.5)]; + [textFieldView sdc_centerInSuperview]; + + [textFieldView addSubview:textField]; + [textField sdc_centerInSuperview]; + [textField sdc_pinWidthToWidthOfView:textFieldView offset:-8]; } @end diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.h b/SDCAlertView/Source/SDCAlertTextFieldViewController.h index 96de4e33..fc447ee1 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.h +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.h @@ -12,4 +12,6 @@ @property (nonatomic, strong) NSArray *textFields; +- (CGFloat)requiredHeightForDisplayingAllTextFields; + @end diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.m b/SDCAlertView/Source/SDCAlertTextFieldViewController.m index 0eed74e7..6f27e7f1 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.m +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.m @@ -18,10 +18,9 @@ - (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerClass:[SDCAlertTextFieldTableViewCell class] forCellReuseIdentifier:SDCAlertTextFieldCellIdentifier]; - UITextField *dummyTextField = [[UITextField alloc] init]; - self.tableView.rowHeight = [dummyTextField intrinsicContentSize].height; + self.tableView.rowHeight = 25; self.tableView.scrollEnabled = NO; - self.tableView.separatorColor = [UIColor clearColor]; + self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.backgroundColor = [UIColor clearColor]; } @@ -32,9 +31,16 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SDCAlertTextFieldTableViewCell *textFieldCell = [tableView dequeueReusableCellWithIdentifier:SDCAlertTextFieldCellIdentifier forIndexPath:indexPath]; - textFieldCell.textField = self.textFields[indexPath.row]; return textFieldCell; } +- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath { + return NO; +} + +- (CGFloat)requiredHeightForDisplayingAllTextFields { + return self.tableView.rowHeight * [self.tableView numberOfRowsInSection:0]; +} + @end From 36ab2a647ede8db046bd24702781bc2825299945 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Thu, 2 Oct 2014 20:42:15 -0700 Subject: [PATCH 28/76] Add contentView --- SDCAlertView/SDCViewController.m | 20 ++++++++++++++-- SDCAlertView/Source/SDCAlertController.h | 2 ++ SDCAlertView/Source/SDCAlertController.m | 24 ++++++++++--------- .../Source/SDCAlertRepresentationView.h | 2 ++ .../Source/SDCAlertRepresentationView.m | 15 ++++++++++-- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index c78c8c73..c26f4bbf 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -43,8 +43,24 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { NSLog(@"%@", action.title); }]]; - [ac addTextFieldWithConfigurationHandler:nil]; - [ac addTextFieldWithConfigurationHandler:nil]; +// [ac addTextFieldWithConfigurationHandler:nil]; +// [ac addTextFieldWithConfigurationHandler:nil]; + + UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; + progressView.progress = 0; + + [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateProgressView:) userInfo:progressView repeats:YES]; + + [progressView setTranslatesAutoresizingMaskIntoConstraints:NO]; + [ac.contentView addSubview:progressView]; + + [progressView sdc_pinWidthToWidthOfView:ac.contentView offset:-20]; + [progressView sdc_horizontallyCenterInSuperview]; + [ac.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(==20)-[progressView]-(==20)-|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(progressView)]]; + [self presentViewController:ac animated:YES completion:nil]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 347b98d3..41b135db 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -50,6 +50,8 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerButtonLayout) { @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *message; +@property (nonatomic, readonly) UIView *contentView; + @property (nonatomic, readonly) SDCAlertControllerStyle preferredStyle; - (void)applyVisualStyle:(id)visualStyle; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index cf5ff331..09d619f2 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -12,6 +12,7 @@ #import "SDCAlertTransition.h" #import "SDCAlertRepresentationView.h" #import "SDCAlertControllerDefaultVisualStyle.h" +#import "SDCIntrinsicallySizedView.h" #import "UIView+SDCAutoLayout.h" @@ -48,6 +49,11 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref _mutableActions = [NSMutableArray array]; _mutableTextFields = [NSMutableArray array]; + _alert = [[SDCAlertRepresentationView alloc] initWithTitle:title message:message]; + _alert.delegate = self; + _alert.contentView = [[SDCIntrinsicallySizedView alloc] init]; + [_alert.contentView setTranslatesAutoresizingMaskIntoConstraints:NO]; + _visualStyle = [[SDCAlertControllerDefaultVisualStyle alloc] init]; _buttonLayout = SDCAlertControllerButtonLayoutAutomatic; @@ -63,7 +69,11 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref - (void)viewDidLoad { [super viewDidLoad]; - self.alert = [self createAlertView]; + self.alert.visualStyle = self.visualStyle; + self.alert.actions = self.actions; + self.alert.buttonLayout = self.buttonLayout; + + [self showTextFieldsInAlertView:self.alert]; [self.view addSubview:self.alert]; [self.alert sdc_centerInSuperview]; @@ -80,16 +90,8 @@ - (void)showTextFieldsInAlertView:(SDCAlertRepresentationView *)alertView { } } -- (SDCAlertRepresentationView *)createAlertView { - SDCAlertRepresentationView *alert = [[SDCAlertRepresentationView alloc] initWithTitle:self.title message:self.message]; - alert.delegate = self; - alert.visualStyle = self.visualStyle; - alert.actions = self.actions; - alert.buttonLayout = self.buttonLayout; - - [self showTextFieldsInAlertView:alert]; - - return alert; +- (UIView *)contentView { + return self.alert.contentView; } #pragma mark - Style diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.h b/SDCAlertView/Source/SDCAlertRepresentationView.h index 02f2b573..5c847dda 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.h +++ b/SDCAlertView/Source/SDCAlertRepresentationView.h @@ -30,6 +30,8 @@ @property (nonatomic, copy) NSArray *actions; @property (nonatomic) SDCAlertControllerButtonLayout buttonLayout; +@property (nonatomic, strong) UIView *contentView; + @property (nonatomic, strong) id visualStyle; - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 25e318de..fb6591ad 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -13,6 +13,7 @@ #import "SDCAlertScrollView.h" #import "SDCAlertControllerCollectionViewFlowLayout.h" #import "SDCAlertCollectionViewCell.h" +#import "SDCIntrinsicallySizedView.h" #import "UIView+SDCAutoLayout.h" @@ -50,7 +51,7 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { _buttonCollectionView.delegate = self; _buttonCollectionView.dataSource = self; _buttonCollectionView.backgroundColor = [UIColor clearColor]; - + [self setTranslatesAutoresizingMaskIntoConstraints:NO]; } @@ -113,8 +114,18 @@ - (void)layoutSubviews { [self.scrollView sdc_setMaximumHeight:[self maximumHeightForScrollView]]; self.scrollView.contentSize = CGSizeMake(self.visualStyle.width, [self.scrollView intrinsicContentSize].height); + UIView *aligningView = self.scrollView; + + if (self.contentView.subviews.count > 0) { + aligningView = self.contentView; + + [self.visualEffectView.contentView addSubview:self.contentView]; + [self.contentView sdc_alignEdges:UIRectEdgeLeft|UIRectEdgeRight withView:self.scrollView]; + [self.contentView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView]; + } + [self.visualEffectView.contentView addSubview:self.buttonCollectionView]; - [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView]; + [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:aligningView inset:0]; [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]; [self.buttonCollectionView sdc_pinHeight:[self heightForButtonCollectionView]]; From 7f7fc924c3b2bcbc6c82926c0d3a8635de0c0aba Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Thu, 2 Oct 2014 22:14:53 -0700 Subject: [PATCH 29/76] Use RBBSpringAnimation for alert animations --- SDCAlertView/SDCViewController.m | 1 + SDCAlertView/Source/SDCAlertTransition.m | 90 ++++++++++++++++++++---- 2 files changed, 78 insertions(+), 13 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index c26f4bbf..401aa3fa 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -38,6 +38,7 @@ - (void)presentNow { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { + self.view.window.layer.speed = 0.1; SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:nil]]; [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { diff --git a/SDCAlertView/Source/SDCAlertTransition.m b/SDCAlertView/Source/SDCAlertTransition.m index 4e2eb209..e74c8515 100644 --- a/SDCAlertView/Source/SDCAlertTransition.m +++ b/SDCAlertView/Source/SDCAlertTransition.m @@ -9,6 +9,7 @@ #import "SDCAlertTransition.h" #import "SDCAlertPresentationController.h" +#import @implementation SDCAlertTransitioningDelegate @@ -40,7 +41,7 @@ - (SDCAlertAnimationController *)animationControllerForPresentation:(BOOL)presen @implementation SDCAlertAnimationController - (NSTimeInterval)transitionDuration:(id)transitionContext { - return .25; + return 0.404; } - (void)animateTransition:(id)transitionContext { @@ -56,20 +57,83 @@ - (void)animateTransition:(id)transitionCo animatingView.frame = [transitionContext finalFrameForViewController:animatingViewController]; - CGAffineTransform presentedTransform = CGAffineTransformIdentity; - CGAffineTransform dismissedTransform = CGAffineTransformMakeScale(0.0001, 0.0001); + if (self.isPresentation) { + [self animatePresentingView:animatingView completion:^{ + [transitionContext completeTransition:YES]; + }]; + } else { + [self animateDismissingView:animatingView completion:^{ + [fromViewController.view removeFromSuperview]; + [transitionContext completeTransition:YES]; + }]; + } +} + +- (void)animatePresentingView:(UIView *)view completion:(void (^)(void))completion { + RBBSpringAnimation *opacityAnimation = [self opacityAnimationFrom:@0 to:@1]; + RBBSpringAnimation *transformAnimation = [self transformAnimationForPresenting]; - animatingView.transform = self.isPresentation ? dismissedTransform : presentedTransform; + view.layer.opacity = 1; + view.layer.transform = [transformAnimation.toValue CATransform3DValue]; - [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ - animatingView.transform = self.isPresentation ? presentedTransform : dismissedTransform; - } completion:^(BOOL finished) { - if (!self.isPresentation) { - [fromViewController.view removeFromSuperview]; - } - - [transitionContext completeTransition:finished]; - }]; + CAAnimationGroup *group = [CAAnimationGroup animation]; + group.animations = @[opacityAnimation, transformAnimation]; + + [self applyAnimation:group toView:view withCompletion:completion]; +} + +- (void)animateDismissingView:(UIView *)view completion:(void(^)(void))completion { + RBBSpringAnimation *opacityAnimation = [self opacityAnimationFrom:@1 to:@0]; + view.alpha = 0; + + [self applyAnimation:opacityAnimation toView:view withCompletion:completion]; +} + +- (void)applyAnimation:(CAAnimation *)animation toView:(UIView *)view withCompletion:(void (^)(void))completion { + [CATransaction begin]; + [CATransaction setCompletionBlock:completion]; + [view.layer addAnimation:animation forKey:@"presentation"]; + [CATransaction commit]; +} + +#pragma mark - Animations + +- (RBBSpringAnimation *)springAnimationForKey:(NSString *)key { + RBBSpringAnimation *animation = [[RBBSpringAnimation alloc] init]; + animation.additive = YES; + animation.keyPath = key; + + animation.duration = [self transitionDuration:nil]; + animation.damping = 45.71; + animation.mass = 1; + animation.stiffness = 522.35; + animation.velocity = 0; + + return animation; +} + +- (RBBSpringAnimation *)opacityAnimationFrom:(NSNumber *)from to:(NSNumber *)to { + RBBSpringAnimation *opacityAnimation = [self springAnimationForKey:@"opacity"]; + opacityAnimation.fromValue = from; + opacityAnimation.toValue = to; + + return opacityAnimation; +} + +#pragma mark Transform + +- (RBBSpringAnimation *)transformAnimationForPresenting { + CATransform3D transformFrom = CATransform3DMakeScale(1.26, 1.26, 1); + CATransform3D transformTo = CATransform3DMakeScale(1, 1, 1); + return [self transformAnimationFrom:transformFrom to:transformTo]; +} + +- (RBBSpringAnimation *)transformAnimationFrom:(CATransform3D)from to:(CATransform3D)to { + RBBSpringAnimation *transformAnimation = [self springAnimationForKey:@"transform"]; + transformAnimation.fromValue = [NSValue valueWithCATransform3D:from]; + transformAnimation.toValue = [NSValue valueWithCATransform3D:to]; + + return transformAnimation; } @end \ No newline at end of file From e872b18e407ce46ae1edd64f019d0b653e22e6b0 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Thu, 2 Oct 2014 22:27:22 -0700 Subject: [PATCH 30/76] Use UIView spring animations --- SDCAlertView/SDCViewController.m | 1 - SDCAlertView/Source/SDCAlertTransition.m | 97 +++++++----------------- 2 files changed, 26 insertions(+), 72 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 401aa3fa..c26f4bbf 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -38,7 +38,6 @@ - (void)presentNow { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { - self.view.window.layer.speed = 0.1; SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:nil]]; [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { diff --git a/SDCAlertView/Source/SDCAlertTransition.m b/SDCAlertView/Source/SDCAlertTransition.m index e74c8515..d3de8eb7 100644 --- a/SDCAlertView/Source/SDCAlertTransition.m +++ b/SDCAlertView/Source/SDCAlertTransition.m @@ -9,7 +9,9 @@ #import "SDCAlertTransition.h" #import "SDCAlertPresentationController.h" -#import + +static CGFloat const SDCAlertAnimationControllerSpringDamping = 45.71; +static CGFloat const SDCAlertAnimationControllerSpringVelocity = 0; @implementation SDCAlertTransitioningDelegate @@ -58,82 +60,35 @@ - (void)animateTransition:(id)transitionCo animatingView.frame = [transitionContext finalFrameForViewController:animatingViewController]; if (self.isPresentation) { - [self animatePresentingView:animatingView completion:^{ - [transitionContext completeTransition:YES]; - }]; + animatingView.transform = CGAffineTransformMakeScale(1.26, 1.26); + animatingView.alpha = 0; + + [self animate:^{ + animatingView.transform = CGAffineTransformMakeScale(1, 1); + animatingView.alpha = 1; + } inContext:transitionContext + withCompletion:^(BOOL finished) { + [transitionContext completeTransition:finished]; + }]; + } else { - [self animateDismissingView:animatingView completion:^{ + [self animate:^{ + animatingView.alpha = 0; + } inContext:transitionContext withCompletion:^(BOOL finished) { [fromViewController.view removeFromSuperview]; - [transitionContext completeTransition:YES]; + [transitionContext completeTransition:finished]; }]; } } -- (void)animatePresentingView:(UIView *)view completion:(void (^)(void))completion { - RBBSpringAnimation *opacityAnimation = [self opacityAnimationFrom:@0 to:@1]; - RBBSpringAnimation *transformAnimation = [self transformAnimationForPresenting]; - - view.layer.opacity = 1; - view.layer.transform = [transformAnimation.toValue CATransform3DValue]; - - CAAnimationGroup *group = [CAAnimationGroup animation]; - group.animations = @[opacityAnimation, transformAnimation]; - - [self applyAnimation:group toView:view withCompletion:completion]; -} - -- (void)animateDismissingView:(UIView *)view completion:(void(^)(void))completion { - RBBSpringAnimation *opacityAnimation = [self opacityAnimationFrom:@1 to:@0]; - view.alpha = 0; - - [self applyAnimation:opacityAnimation toView:view withCompletion:completion]; -} - -- (void)applyAnimation:(CAAnimation *)animation toView:(UIView *)view withCompletion:(void (^)(void))completion { - [CATransaction begin]; - [CATransaction setCompletionBlock:completion]; - [view.layer addAnimation:animation forKey:@"presentation"]; - [CATransaction commit]; -} - -#pragma mark - Animations - -- (RBBSpringAnimation *)springAnimationForKey:(NSString *)key { - RBBSpringAnimation *animation = [[RBBSpringAnimation alloc] init]; - animation.additive = YES; - animation.keyPath = key; - - animation.duration = [self transitionDuration:nil]; - animation.damping = 45.71; - animation.mass = 1; - animation.stiffness = 522.35; - animation.velocity = 0; - - return animation; -} - -- (RBBSpringAnimation *)opacityAnimationFrom:(NSNumber *)from to:(NSNumber *)to { - RBBSpringAnimation *opacityAnimation = [self springAnimationForKey:@"opacity"]; - opacityAnimation.fromValue = from; - opacityAnimation.toValue = to; - - return opacityAnimation; -} - -#pragma mark Transform - -- (RBBSpringAnimation *)transformAnimationForPresenting { - CATransform3D transformFrom = CATransform3DMakeScale(1.26, 1.26, 1); - CATransform3D transformTo = CATransform3DMakeScale(1, 1, 1); - return [self transformAnimationFrom:transformFrom to:transformTo]; -} - -- (RBBSpringAnimation *)transformAnimationFrom:(CATransform3D)from to:(CATransform3D)to { - RBBSpringAnimation *transformAnimation = [self springAnimationForKey:@"transform"]; - transformAnimation.fromValue = [NSValue valueWithCATransform3D:from]; - transformAnimation.toValue = [NSValue valueWithCATransform3D:to]; - - return transformAnimation; +- (void)animate:(void(^)(void))animations inContext:(id)context withCompletion:(void(^)(BOOL finished))completion { + [UIView animateWithDuration:[self transitionDuration:context] + delay:0 + usingSpringWithDamping:SDCAlertAnimationControllerSpringDamping + initialSpringVelocity:SDCAlertAnimationControllerSpringVelocity + options:0 + animations:animations + completion:completion]; } @end \ No newline at end of file From b83a1495781664ba815978982d1b3796bfb5d15e Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Thu, 2 Oct 2014 22:48:31 -0700 Subject: [PATCH 31/76] Let user prevent dismissal --- SDCAlertView/SDCViewController.m | 1 + SDCAlertView/Source/SDCAlertController.h | 3 ++- SDCAlertView/Source/SDCAlertController.m | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index c26f4bbf..44daab5f 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -43,6 +43,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { NSLog(@"%@", action.title); }]]; + // [ac addTextFieldWithConfigurationHandler:nil]; // [ac addTextFieldWithConfigurationHandler:nil]; diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 41b135db..35e78fd1 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -53,7 +53,8 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerButtonLayout) { @property (nonatomic, readonly) UIView *contentView; @property (nonatomic, readonly) SDCAlertControllerStyle preferredStyle; - - (void)applyVisualStyle:(id)visualStyle; +@property (nonatomic, copy) BOOL (^shouldDismissBlock)(SDCAlertAction *action); + @end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 09d619f2..27b0faf2 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -115,7 +115,7 @@ - (NSArray *)actions { } - (void)alertRepresentationView:(SDCAlertRepresentationView *)sender didPerformAction:(SDCAlertAction *)action { - if (!action.isEnabled) { + if (!action.isEnabled || (self.shouldDismissBlock && !self.shouldDismissBlock(action))) { return; } From 1e3b064091c19d0145e43ab3301d6ab06cae5477 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Thu, 2 Oct 2014 23:18:37 -0700 Subject: [PATCH 32/76] Allow attributed strings for title and message labels --- SDCAlertView/Source/SDCAlertController.h | 6 ++ SDCAlertView/Source/SDCAlertController.m | 63 ++++++++++++++----- .../Source/SDCAlertRepresentationView.h | 6 +- .../Source/SDCAlertRepresentationView.m | 2 +- SDCAlertView/Source/SDCAlertScrollView.h | 2 +- SDCAlertView/Source/SDCAlertScrollView.m | 14 ++--- 6 files changed, 67 insertions(+), 26 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 35e78fd1..6253292e 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -39,6 +39,9 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerButtonLayout) { @interface SDCAlertController : UIViewController + (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(SDCAlertControllerStyle)preferredStyle; ++ (instancetype)alertControllerWithAttributedTitle:(NSAttributedString *)attributedTitle + attributedMessage:(NSAttributedString *)attributedMessage + preferredStyle:(SDCAlertControllerStyle)preferredStyle; - (void)addAction:(SDCAlertAction *)action; @property (nonatomic, readonly) NSArray *actions; @@ -48,7 +51,10 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerButtonLayout) { @property (nonatomic, readonly) NSArray *textFields; @property (nonatomic, copy) NSString *title; +@property (nonatomic, copy) NSAttributedString *attributedTitle; + @property (nonatomic, copy) NSString *message; +@property (nonatomic, copy) NSAttributedString *attributedMessage; @property (nonatomic, readonly) UIView *contentView; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 27b0faf2..e0b81c23 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -30,30 +30,27 @@ @interface SDCAlertController () @implementation SDCAlertController -#pragma mark - Creation +#pragma mark - Initialization + (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(SDCAlertControllerStyle)preferredStyle { - SDCAlertController *alert = [[self alloc] initWithTitle:title message:message preferredStyle:preferredStyle]; - return alert; + return [[self alloc] initWithTitle:title message:message style:preferredStyle]; } -- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(SDCAlertControllerStyle)preferredStyle { - self = [self init]; - - NSAssert(preferredStyle == SDCAlertControllerStyleAlert, @"Only SDCAlertControllerStyleAlert is supported by %@", NSStringFromClass([self class])); ++ (instancetype)alertControllerWithAttributedTitle:(NSAttributedString *)attributedTitle + attributedMessage:(NSAttributedString *)attributedMessage + preferredStyle:(SDCAlertControllerStyle)preferredStyle { + return [[self alloc] initWithAttributedTitle:attributedTitle attributedMessage:attributedMessage style:preferredStyle]; +} + +- (instancetype)initWithStyle:(SDCAlertControllerStyle)style { + self = [super init]; if (self) { - self.title = title; - _message = message; + NSAssert(style == SDCAlertControllerStyleAlert, @"Only SDCAlertControllerStyleAlert is supported by %@", NSStringFromClass([self class])); _mutableActions = [NSMutableArray array]; _mutableTextFields = [NSMutableArray array]; - _alert = [[SDCAlertRepresentationView alloc] initWithTitle:title message:message]; - _alert.delegate = self; - _alert.contentView = [[SDCIntrinsicallySizedView alloc] init]; - [_alert.contentView setTranslatesAutoresizingMaskIntoConstraints:NO]; - _visualStyle = [[SDCAlertControllerDefaultVisualStyle alloc] init]; _buttonLayout = SDCAlertControllerButtonLayoutAutomatic; @@ -64,8 +61,46 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message pref return self; } +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message style:(SDCAlertControllerStyle)style { + self = [self initWithStyle:style]; + + if (self) { + self.title = title; + _message = message; + + [self createAlert]; + } + + return self; +} + +- (instancetype)initWithAttributedTitle:(NSAttributedString *)attributedTitle + attributedMessage:(NSAttributedString *)attributedMessage + style:(SDCAlertControllerStyle)style { + self = [self initWithStyle:style]; + + if (self) { + _attributedTitle = attributedTitle; + _attributedMessage = attributedMessage; + + [self createAlert]; + } + + return self; +} + #pragma mark - Alert View +- (void)createAlert { + NSAttributedString *title = self.attributedTitle ? : [[NSAttributedString alloc] initWithString:self.title]; + NSAttributedString *message = self.attributedMessage ? : [[NSAttributedString alloc] initWithString:self.message]; + self.alert = [[SDCAlertRepresentationView alloc] initWithTitle:title message:message]; + + self.alert.delegate = self; + self.alert.contentView = [[SDCIntrinsicallySizedView alloc] init]; + [self.alert.contentView setTranslatesAutoresizingMaskIntoConstraints:NO]; +} + - (void)viewDidLoad { [super viewDidLoad]; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.h b/SDCAlertView/Source/SDCAlertRepresentationView.h index 5c847dda..96e6d6d5 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.h +++ b/SDCAlertView/Source/SDCAlertRepresentationView.h @@ -24,8 +24,8 @@ @property (nonatomic, weak) id delegate; -@property (nonatomic, copy) NSString *title; -@property (nonatomic, copy) NSString *message; +@property (nonatomic, copy) NSAttributedString *title; +@property (nonatomic, copy) NSAttributedString *message; @property (nonatomic, copy) NSArray *actions; @property (nonatomic) SDCAlertControllerButtonLayout buttonLayout; @@ -34,7 +34,7 @@ @property (nonatomic, strong) id visualStyle; -- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; +- (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedString *)message; - (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index fb6591ad..c1d6c573 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -28,7 +28,7 @@ @interface SDCAlertRepresentationView () visualStyle; -- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message; +- (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedString *)message; @end diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index d88e64f9..7e485860 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -14,15 +14,15 @@ #import "UIView+SDCAutoLayout.h" @interface SDCAlertScrollView () -@property (nonatomic, strong) NSString *title; +@property (nonatomic, strong) NSAttributedString *title; @property (nonatomic, strong) SDCAlertLabel *titleLabel; -@property (nonatomic, strong) NSString *message; +@property (nonatomic, strong) NSAttributedString *message; @property (nonatomic, strong) SDCAlertLabel *messageLabel; @end @implementation SDCAlertScrollView -- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { +- (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedString *)message { self = [self init]; if (self) { @@ -41,14 +41,14 @@ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message { return self; } -- (void)setTitle:(NSString *)title { +- (void)setTitle:(NSAttributedString *)title { _title = title; - _titleLabel.text = title; + _titleLabel.attributedText = title; } -- (void)setMessage:(NSString *)message { +- (void)setMessage:(NSAttributedString *)message { _message = message; - _messageLabel.text = message; + _messageLabel.attributedText = message; } - (void)setVisualStyle:(id)visualStyle { From f5345927271c7989553c5bd7ad159d89121de700 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Thu, 2 Oct 2014 23:44:21 -0700 Subject: [PATCH 33/76] Add support for attributed button titles --- SDCAlertView/SDCViewController.m | 4 ++- SDCAlertView/Source/SDCAlertAction.m | 32 ++++++++++++++++--- SDCAlertView/Source/SDCAlertController.h | 3 ++ .../Source/SDCAlertRepresentationView.m | 8 +++-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 44daab5f..30142b83 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -63,7 +63,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath views:NSDictionaryOfVariableBindings(progressView)]]; - [self presentViewController:ac animated:YES completion:nil]; + [self presentViewController:ac animated:YES completion:^{ + ac.title = @"New title"; + }]; // [self presentNow]; } else if (indexPath.section == 1) { diff --git a/SDCAlertView/Source/SDCAlertAction.m b/SDCAlertView/Source/SDCAlertAction.m index 398a44cb..ecf40c5d 100644 --- a/SDCAlertView/Source/SDCAlertAction.m +++ b/SDCAlertView/Source/SDCAlertAction.m @@ -17,15 +17,17 @@ @implementation SDCAlertAction #pragma mark - Initialization + (instancetype)actionWithTitle:(NSString *)title style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *))handler { - SDCAlertAction *action = [[self alloc] initWithTitle:title style:style handler:handler]; - return action; + return [[self alloc] initWithTitle:title style:style handler:handler]; } -- (instancetype)initWithTitle:(NSString *)title style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *))handler { - self = [self init]; ++ (instancetype)actionWithAttributedTitle:(NSAttributedString *)attributedTitle style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *))handler { + return [[self alloc] initWithAttributedTitle:attributedTitle style:style handler:handler]; +} + +- (instancetype)initWithStyle:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *action))handler { + self = [super init]; if (self) { - _title = title; _style = style; _enabled = YES; _handler = handler; @@ -34,6 +36,26 @@ - (instancetype)initWithTitle:(NSString *)title style:(SDCAlertActionStyle)style return self; } +- (instancetype)initWithTitle:(NSString *)title style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *))handler { + self = [self initWithStyle:style handler:handler]; + + if (self) { + _title = title; + } + + return self; +} + +- (instancetype)initWithAttributedTitle:(NSAttributedString *)attributedTitle style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *handler))handler { + self = [self initWithStyle:style handler:handler]; + + if (self) { + _attributedTitle = attributedTitle; + } + + return self; +} + #pragma mark - NSCopying - (id)copyWithZone:(NSZone *)zone { diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 6253292e..95b8131f 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -27,8 +27,11 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerButtonLayout) { @interface SDCAlertAction : NSObject + (instancetype)actionWithTitle:(NSString *)title style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *action))handler; ++ (instancetype)actionWithAttributedTitle:(NSAttributedString *)attributedTitle style:(SDCAlertActionStyle)style handler:(void (^)(SDCAlertAction *action))handler; @property (nonatomic, readonly) NSString *title; +@property (nonatomic, readonly) NSAttributedString *attributedTitle; + @property (nonatomic, readonly) SDCAlertActionStyle style; @property (nonatomic, getter=isEnabled) BOOL enabled; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index c1d6c573..5ca239ed 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -159,12 +159,16 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell SDCAlertAction *action = self.actions[indexPath.item]; cell.visualStyle = self.visualStyle; cell.textLabel.font = [self.visualStyle fontForButtonRepresentingAction:action]; - cell.textLabel.text = action.title; cell.textLabel.textColor = [self.visualStyle textColorForButtonRepresentingAction:action]; cell.textLabel.enabled = action.isEnabled; - cell.gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionButtonTapped:)]; + if (action.attributedTitle) { + cell.textLabel.attributedText = action.attributedTitle; + } else { + cell.textLabel.text = action.title; + } + return cell; } From eb62c0d68d619bbff5a34e082e4ffb00af5a4bd4 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Thu, 2 Oct 2014 23:44:47 -0700 Subject: [PATCH 34/76] Update labels when setting title/message after initialization --- SDCAlertView/Source/SDCAlertController.m | 10 +++++++++ .../Source/SDCAlertRepresentationView.m | 16 ++++++++++++++ SDCAlertView/Source/SDCAlertScrollView.h | 3 +++ SDCAlertView/Source/SDCAlertScrollView.m | 21 +++++++++++-------- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index e0b81c23..cf98a173 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -89,6 +89,16 @@ - (instancetype)initWithAttributedTitle:(NSAttributedString *)attributedTitle return self; } +- (void)setTitle:(NSString *)title { + [super setTitle:title]; + self.alert.title = [[NSAttributedString alloc] initWithString:title]; +} + +- (void)setMessage:(NSString *)message { + _message = message; + self.alert.message = [[NSAttributedString alloc] initWithString:message]; +} + #pragma mark - Alert View - (void)createAlert { diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 5ca239ed..d0dd34b9 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -58,6 +58,22 @@ - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedS return self; } +- (NSAttributedString *)title { + return self.scrollView.title; +} + +- (void)setTitle:(NSAttributedString *)title { + self.scrollView.title = title; +} + +- (NSAttributedString *)message { + return self.scrollView.message; +} + +- (void)setMessage:(NSAttributedString *)message { + self.scrollView.message = message; +} + - (void)setButtonLayout:(SDCAlertControllerButtonLayout)buttonLayout { _buttonLayout = buttonLayout; diff --git a/SDCAlertView/Source/SDCAlertScrollView.h b/SDCAlertView/Source/SDCAlertScrollView.h index 542cf844..afdd16a2 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.h +++ b/SDCAlertView/Source/SDCAlertScrollView.h @@ -14,6 +14,9 @@ @interface SDCAlertScrollView : UIScrollView +@property (nonatomic, strong) NSAttributedString *title; +@property (nonatomic, strong) NSAttributedString *message; + @property (nonatomic, strong) SDCAlertTextFieldViewController *textFieldViewController; @property (nonatomic, strong) id visualStyle; diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index 7e485860..d64d926d 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -14,9 +14,7 @@ #import "UIView+SDCAutoLayout.h" @interface SDCAlertScrollView () -@property (nonatomic, strong) NSAttributedString *title; @property (nonatomic, strong) SDCAlertLabel *titleLabel; -@property (nonatomic, strong) NSAttributedString *message; @property (nonatomic, strong) SDCAlertLabel *messageLabel; @end @@ -27,28 +25,33 @@ - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedS if (self) { _titleLabel = [[SDCAlertLabel alloc] init]; + _titleLabel.attributedText = title; [self addSubview:_titleLabel]; _messageLabel = [[SDCAlertLabel alloc] init]; + _messageLabel.attributedText = message; [self addSubview:_messageLabel]; - self.title = title; - self.message = message; - [self setTranslatesAutoresizingMaskIntoConstraints:NO]; } return self; } +- (NSAttributedString *)title { + return self.messageLabel.attributedText; +} + - (void)setTitle:(NSAttributedString *)title { - _title = title; - _titleLabel.attributedText = title; + self.titleLabel.attributedText = title; +} + +- (NSAttributedString *)message { + return self.messageLabel.attributedText; } - (void)setMessage:(NSAttributedString *)message { - _message = message; - _messageLabel.attributedText = message; + self.messageLabel.attributedText = message; } - (void)setVisualStyle:(id)visualStyle { From bf925be4c05f60306f5632d7888ae04fe3cca1c2 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Fri, 3 Oct 2014 22:17:16 -0700 Subject: [PATCH 35/76] Refactor collection view cell logic --- .../Source/SDCAlertCollectionViewCell.h | 8 +++-- .../Source/SDCAlertCollectionViewCell.m | 30 ++++++++++++++----- .../Source/SDCAlertRepresentationView.m | 12 +------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.h b/SDCAlertView/Source/SDCAlertCollectionViewCell.h index c3e94458..3b3f1d09 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.h +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.h @@ -8,15 +8,17 @@ #import -#import "SDCAlertControllerVisualStyle.h" +@class SDCAlertAction; +@protocol SDCAlertControllerVisualStyle; @interface SDCAlertControllerSeparatorView : UICollectionReusableView @end @interface SDCAlertCollectionViewCell : UICollectionViewCell -@property (nonatomic, strong) id visualStyle; -@property (nonatomic, strong) UILabel *textLabel; @property (nonatomic, strong) UIGestureRecognizer *gestureRecognizer; + +- (void)updateWithAction:(SDCAlertAction *)action visualStyle:(id)visualStyle; + @end diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index a0b66889..35061bad 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -8,9 +8,14 @@ #import "SDCAlertCollectionViewCell.h" +#import "SDCAlertController.h" // SDCAlertAction +#import "SDCAlertControllerVisualStyle.h" + #import "UIView+SDCAutoLayout.h" @interface SDCAlertCollectionViewCell () +@property (nonatomic, strong) UILabel *textLabel; +@property (nonatomic, getter=isEnabled) BOOL enabled; @property (nonatomic, strong) UIView *highlightedBackgroundView; @end @@ -27,14 +32,6 @@ - (instancetype)initWithFrame:(CGRect)frame { return self; } -- (void)setVisualStyle:(id)visualStyle { - _visualStyle = visualStyle; - - self.highlightedBackgroundView = visualStyle.buttonHighlightBackgroundView; - [self.highlightedBackgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; - self.highlightedBackgroundView.hidden = !self.isHighlighted; -} - - (void)setGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { [self removeGestureRecognizer:_gestureRecognizer]; @@ -42,6 +39,23 @@ - (void)setGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { [self addGestureRecognizer:gestureRecognizer]; } +- (void)updateWithAction:(SDCAlertAction *)action visualStyle:(id)visualStyle { + if (action.attributedTitle) { + self.textLabel.attributedText = action.attributedTitle; + } else { + self.textLabel.text = action.title; + } + + self.enabled = action.isEnabled; + + self.textLabel.font = [visualStyle fontForButtonRepresentingAction:action]; + self.textLabel.textColor = [visualStyle textColorForButtonRepresentingAction:action]; + + self.highlightedBackgroundView = visualStyle.buttonHighlightBackgroundView; + [self.highlightedBackgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; + self.highlightedBackgroundView.hidden = !self.isHighlighted; +} + - (void)layoutSubviews { [super layoutSubviews]; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index d0dd34b9..8df9342b 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -173,18 +173,8 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell forIndexPath:indexPath]; SDCAlertAction *action = self.actions[indexPath.item]; - cell.visualStyle = self.visualStyle; - cell.textLabel.font = [self.visualStyle fontForButtonRepresentingAction:action]; - cell.textLabel.textColor = [self.visualStyle textColorForButtonRepresentingAction:action]; - cell.textLabel.enabled = action.isEnabled; + [cell updateWithAction:action visualStyle:self.visualStyle]; cell.gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionButtonTapped:)]; - - if (action.attributedTitle) { - cell.textLabel.attributedText = action.attributedTitle; - } else { - cell.textLabel.text = action.title; - } - return cell; } From 1aa1516074c9841d54a61aede6c87308a5c1dd13 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Fri, 3 Oct 2014 22:47:05 -0700 Subject: [PATCH 36/76] Add convenience present and dismiss methods --- SDCAlertView.xcodeproj/project.pbxproj | 6 ++++ SDCAlertView/SDCViewController.m | 6 ++-- SDCAlertView/Source/SDCAlertController.h | 11 +++++++ SDCAlertView/Source/SDCAlertController.m | 28 ++++++++++++++++- .../Source/UIViewController+Current.h | 15 +++++++++ .../Source/UIViewController+Current.m | 31 +++++++++++++++++++ 6 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 SDCAlertView/Source/UIViewController+Current.h create mode 100644 SDCAlertView/Source/UIViewController+Current.m diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index b4c43238..dc6f8400 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ D2A5E0D119D3D6A90034B709 /* SDCAlertCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */; }; D2A6A0DB19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */; }; D2A6F1C519D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */; }; + D2AE983119DFBDF50083AB0C /* UIViewController+Current.m in Sources */ = {isa = PBXBuildFile; fileRef = D2AE983019DFBDF50083AB0C /* UIViewController+Current.m */; }; D2BD0CC418FEB2C400520E33 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC318FEB2C400520E33 /* iPad.storyboard */; }; D2BD0CC618FED65700520E33 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC518FED65700520E33 /* CHANGELOG.md */; }; D2D5A77019D8A64B00386078 /* SDCAlertTextFieldViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */; }; @@ -113,6 +114,8 @@ D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerCollectionViewFlowLayout.m; sourceTree = ""; }; D2A6F1C319D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertTextFieldTableViewCell.h; sourceTree = ""; }; D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertTextFieldTableViewCell.m; sourceTree = ""; }; + D2AE982F19DFBDF50083AB0C /* UIViewController+Current.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Current.h"; sourceTree = ""; }; + D2AE983019DFBDF50083AB0C /* UIViewController+Current.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Current.m"; sourceTree = ""; }; D2BD0CC318FEB2C400520E33 /* iPad.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = iPad.storyboard; sourceTree = ""; }; D2BD0CC518FED65700520E33 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CHANGELOG.md; sourceTree = ""; }; D2D5A76E19D8A64B00386078 /* SDCAlertTextFieldViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertTextFieldViewController.h; sourceTree = ""; }; @@ -257,6 +260,8 @@ D26506EF19C61B8000BF34B9 /* 2.0 */ = { isa = PBXGroup; children = ( + D2AE982F19DFBDF50083AB0C /* UIViewController+Current.h */, + D2AE983019DFBDF50083AB0C /* UIViewController+Current.m */, D2D5A76E19D8A64B00386078 /* SDCAlertTextFieldViewController.h */, D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */, D2A6F1C319D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.h */, @@ -481,6 +486,7 @@ D263F1131829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m in Sources */, D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */, D263F1101829D1860001E4E0 /* SDCAlertViewController.m in Sources */, + D2AE983119DFBDF50083AB0C /* UIViewController+Current.m in Sources */, D2FA54941894AFB5006FAB5E /* SDCAlertViewCoordinator.m in Sources */, D2666A4619CFE0F900167157 /* SDCAlertLabel.m in Sources */, D25B3CB817ECE7A6004B32A2 /* SDCAppDelegate.m in Sources */, diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 30142b83..1eb70d3a 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -63,8 +63,10 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath views:NSDictionaryOfVariableBindings(progressView)]]; - [self presentViewController:ac animated:YES completion:^{ - ac.title = @"New title"; + [ac presentWithCompletion:^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [ac dismiss]; + }); }]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 95b8131f..4f39cbeb 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -66,4 +66,15 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerButtonLayout) { @property (nonatomic, copy) BOOL (^shouldDismissBlock)(SDCAlertAction *action); +@end + +@interface SDCAlertController (Transitioning) + +- (void)present; +- (void)presentWithCompletion:(void(^)(void))completion; +- (void)presentFromViewController:(UIViewController *)viewController completionHandler:(void(^)(void))completion; + +- (void)dismiss; +- (void)dismissWithCompletion:(void(^)(void))completion; + @end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index cf98a173..1ced6d36 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -15,6 +15,7 @@ #import "SDCIntrinsicallySizedView.h" #import "UIView+SDCAutoLayout.h" +#import "UIViewController+Current.h" @interface SDCAlertAction (Private) @property (nonatomic, copy) void (^handler)(SDCAlertAction *); @@ -164,7 +165,7 @@ - (void)alertRepresentationView:(SDCAlertRepresentationView *)sender didPerformA return; } - [self.presentingViewController dismissViewControllerAnimated:YES completion:^{ + [self dismissWithCompletion:^{ if (action.handler) { action.handler(action); } @@ -187,4 +188,29 @@ - (NSArray *)textFields { return [self.mutableTextFields copy]; } +@end + +@implementation SDCAlertController (Presentation) + +- (void)present { + [self presentWithCompletion:nil]; +} + +- (void)presentWithCompletion:(void(^)(void))completion { + UIViewController *currentViewController = [UIViewController currentViewController]; + [self presentFromViewController:currentViewController completionHandler:completion]; +} + +- (void)presentFromViewController:(UIViewController *)viewController completionHandler:(void (^)(void))completionHandler { + [viewController presentViewController:self animated:YES completion:completionHandler]; +} + +- (void)dismiss { + [self dismissWithCompletion:nil]; +} + +- (void)dismissWithCompletion:(void (^)(void))completion { + [self.presentingViewController dismissViewControllerAnimated:YES completion:completion]; +} + @end \ No newline at end of file diff --git a/SDCAlertView/Source/UIViewController+Current.h b/SDCAlertView/Source/UIViewController+Current.h new file mode 100644 index 00000000..f8214832 --- /dev/null +++ b/SDCAlertView/Source/UIViewController+Current.h @@ -0,0 +1,15 @@ +// +// UIViewController+Current.h +// SDCAlertView +// +// Created by Scott Berrevoets on 10/3/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +@import UIKit; + +@interface UIViewController (Current) + ++ (UIViewController *)currentViewController; + +@end diff --git a/SDCAlertView/Source/UIViewController+Current.m b/SDCAlertView/Source/UIViewController+Current.m new file mode 100644 index 00000000..0b352c4a --- /dev/null +++ b/SDCAlertView/Source/UIViewController+Current.m @@ -0,0 +1,31 @@ +// +// UIViewController+Current.m +// SDCAlertView +// +// Created by Scott Berrevoets on 10/3/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "UIViewController+Current.h" + +@implementation UIViewController (Current) + ++ (UIViewController *)currentViewController { + UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController]; + return [self topViewControllerForViewController:rootViewController]; +} + ++ (UIViewController *)topViewControllerForViewController:(UIViewController *)rootViewController { + if ([rootViewController isKindOfClass:[UINavigationController class]]) { + UINavigationController *navigationController = (UINavigationController *)rootViewController; + return [self topViewControllerForViewController:navigationController.visibleViewController]; + } + + if (rootViewController.presentedViewController) { + return [self topViewControllerForViewController:rootViewController.presentedViewController]; + } + + return rootViewController; +} + +@end From 4f4ed54be90e7ce972cf8b54be9a32fc4799a9f3 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Fri, 3 Oct 2014 23:01:57 -0700 Subject: [PATCH 37/76] Add convenience methods --- SDCAlertView/SDCViewController.m | 13 +++++++------ SDCAlertView/Source/SDCAlertController.h | 8 ++++++++ SDCAlertView/Source/SDCAlertController.m | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 1eb70d3a..ec72406b 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -62,12 +62,13 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath metrics:nil views:NSDictionaryOfVariableBindings(progressView)]]; - - [ac presentWithCompletion:^{ - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [ac dismiss]; - }); - }]; + + [SDCAlertController showAlertControllerWithTitle:@"Title" message:@"Message" actionTitle:@"OK"]; +// [ac presentWithCompletion:^{ +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ +// [ac dismiss]; +// }); +// }]; // [self presentNow]; } else if (indexPath.section == 1) { diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 4f39cbeb..4525a285 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -77,4 +77,12 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerButtonLayout) { - (void)dismiss; - (void)dismissWithCompletion:(void(^)(void))completion; +@end + +@interface SDCAlertController (Convenience) + ++ (instancetype)showAlertControllerWithTitle:(NSString *)title message:(NSString *)message; ++ (instancetype)showAlertControllerWithTitle:(NSString *)title message:(NSString *)message actionTitle:(NSString *)actionTitle; ++ (instancetype)showAlertControllerWithTitle:(NSString *)title message:(NSString *)message actionTitle:(NSString *)actionTitle subview:(UIView *)subview; + @end \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 1ced6d36..cb22c78c 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -213,4 +213,28 @@ - (void)dismissWithCompletion:(void (^)(void))completion { [self.presentingViewController dismissViewControllerAnimated:YES completion:completion]; } +@end + +@implementation SDCAlertController (Convenience) + ++ (instancetype)showAlertControllerWithTitle:(NSString *)title message:(NSString *)message { + return [self showAlertControllerWithTitle:title message:message actionTitle:nil]; +} + ++ (instancetype)showAlertControllerWithTitle:(NSString *)title message:(NSString *)message actionTitle:(NSString *)actionTitle { + return [self showAlertControllerWithTitle:title message:message actionTitle:actionTitle subview:nil]; +} + ++ (instancetype)showAlertControllerWithTitle:(NSString *)title message:(NSString *)message actionTitle:(NSString *)actionTitle subview:(UIView *)subview { + SDCAlertController *controller = [SDCAlertController alertControllerWithTitle:title message:message preferredStyle:SDCAlertControllerStyleAlert]; + [controller addAction:[SDCAlertAction actionWithTitle:actionTitle style:SDCAlertActionStyleCancel handler:nil]]; + + if (subview) { + [controller.contentView addSubview:subview]; + } + + [controller present]; + return controller; +} + @end \ No newline at end of file From 8a3f57a957c04c31da45b3f806aca486d5a38293 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Fri, 3 Oct 2014 23:10:30 -0700 Subject: [PATCH 38/76] Use variable button top spacing --- SDCAlertView/SDCViewController.m | 14 +++++++------- .../Source/SDCAlertControllerDefaultVisualStyle.m | 8 ++++++++ .../Source/SDCAlertControllerVisualStyle.h | 2 ++ SDCAlertView/Source/SDCAlertRepresentationView.m | 4 +++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index ec72406b..a270da0e 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -63,13 +63,13 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath views:NSDictionaryOfVariableBindings(progressView)]]; - [SDCAlertController showAlertControllerWithTitle:@"Title" message:@"Message" actionTitle:@"OK"]; -// [ac presentWithCompletion:^{ -// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ -// [ac dismiss]; -// }); -// }]; -// [self presentNow]; + //[SDCAlertController showAlertControllerWithTitle:@"Title" message:@"Message" actionTitle:@"OK"]; + [ac presentWithCompletion:^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [ac dismiss]; + }); + }]; + // [self presentNow]; } else if (indexPath.section == 1) { if (indexPath.row == 0) { diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index fdd27e83..0a787935 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -24,6 +24,14 @@ - (CGFloat)minimumButtonWidth { return 90; // Fits exactly three buttons without scrolling } +- (CGFloat)buttonTopSpacingWithContentView { + return 0; +} + +- (CGFloat)buttonTopSpacingWithoutContentView { + return 20; +} + - (UIEdgeInsets)margins { return UIEdgeInsetsMake(3, 0, 3, 0); } diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index da347b6f..111d2ecc 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -14,6 +14,8 @@ @property (nonatomic, readonly) CGFloat width; @property (nonatomic, readonly) CGFloat buttonHeight; +@property (nonatomic, readonly) CGFloat buttonTopSpacingWithContentView; +@property (nonatomic, readonly) CGFloat buttonTopSpacingWithoutContentView; @property (nonatomic, readonly) CGFloat minimumButtonWidth; // For forced horizontal layout and 3+ buttons @property (nonatomic, readonly) UIEdgeInsets margins; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertRepresentationView.m index 8df9342b..fb595e24 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertRepresentationView.m @@ -131,9 +131,11 @@ - (void)layoutSubviews { self.scrollView.contentSize = CGSizeMake(self.visualStyle.width, [self.scrollView intrinsicContentSize].height); UIView *aligningView = self.scrollView; + CGFloat buttonTopSpacing = self.visualStyle.buttonTopSpacingWithoutContentView; if (self.contentView.subviews.count > 0) { aligningView = self.contentView; + buttonTopSpacing = self.visualStyle.buttonTopSpacingWithContentView; [self.visualEffectView.contentView addSubview:self.contentView]; [self.contentView sdc_alignEdges:UIRectEdgeLeft|UIRectEdgeRight withView:self.scrollView]; @@ -141,7 +143,7 @@ - (void)layoutSubviews { } [self.visualEffectView.contentView addSubview:self.buttonCollectionView]; - [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:aligningView inset:0]; + [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:aligningView inset:buttonTopSpacing]; [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]; [self.buttonCollectionView sdc_pinHeight:[self heightForButtonCollectionView]]; From e1a6ec7259a7ff378a281c2ec1f70e6dd2d28493 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 4 Oct 2014 19:10:02 -0700 Subject: [PATCH 39/76] Rename SDCAlertRepresentationView to SDCAlertControllerView --- SDCAlertView.xcodeproj/project.pbxproj | 12 ++++++------ SDCAlertView/Source/SDCAlertController.m | 12 ++++++------ ...RepresentationView.h => SDCAlertControllerView.h} | 12 ++++++------ ...RepresentationView.m => SDCAlertControllerView.m} | 10 +++++----- 4 files changed, 23 insertions(+), 23 deletions(-) rename SDCAlertView/Source/{SDCAlertRepresentationView.h => SDCAlertControllerView.h} (70%) rename SDCAlertView/Source/{SDCAlertRepresentationView.m => SDCAlertControllerView.m} (96%) diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index dc6f8400..456c59c2 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -29,7 +29,7 @@ D263F1161829D31E0001E4E0 /* SDCAlertViewContentView.m in Sources */ = {isa = PBXBuildFile; fileRef = D263F1151829D31E0001E4E0 /* SDCAlertViewContentView.m */; }; D26506F219C67FC300BF34B9 /* SDCAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F119C67FC300BF34B9 /* SDCAlertController.m */; }; D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F319C6812600BF34B9 /* SDCAlertAction.m */; }; - D2666A4019CFDE2800167157 /* SDCAlertRepresentationView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A3F19CFDE2800167157 /* SDCAlertRepresentationView.m */; }; + D2666A4019CFDE2800167157 /* SDCAlertControllerView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A3F19CFDE2800167157 /* SDCAlertControllerView.m */; }; D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */; }; D2666A4619CFE0F900167157 /* SDCAlertLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4519CFE0F900167157 /* SDCAlertLabel.m */; }; D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */ = {isa = PBXBuildFile; fileRef = D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */; }; @@ -95,8 +95,8 @@ D26506F019C67FC300BF34B9 /* SDCAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertController.h; sourceTree = ""; }; D26506F119C67FC300BF34B9 /* SDCAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertController.m; sourceTree = ""; }; D26506F319C6812600BF34B9 /* SDCAlertAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertAction.m; sourceTree = ""; }; - D2666A3E19CFDE2800167157 /* SDCAlertRepresentationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertRepresentationView.h; sourceTree = ""; }; - D2666A3F19CFDE2800167157 /* SDCAlertRepresentationView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertRepresentationView.m; sourceTree = ""; }; + D2666A3E19CFDE2800167157 /* SDCAlertControllerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerView.h; sourceTree = ""; }; + D2666A3F19CFDE2800167157 /* SDCAlertControllerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerView.m; sourceTree = ""; }; D2666A4119CFDF6700167157 /* SDCAlertScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertScrollView.h; sourceTree = ""; }; D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertScrollView.m; sourceTree = ""; }; D2666A4419CFE0F900167157 /* SDCAlertLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertLabel.h; sourceTree = ""; }; @@ -267,8 +267,8 @@ D2A6F1C319D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.h */, D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */, D2988E0519D7960900140116 /* SDCAlertControllerVisualStyle.h */, - D2666A3E19CFDE2800167157 /* SDCAlertRepresentationView.h */, - D2666A3F19CFDE2800167157 /* SDCAlertRepresentationView.m */, + D2666A3E19CFDE2800167157 /* SDCAlertControllerView.h */, + D2666A3F19CFDE2800167157 /* SDCAlertControllerView.m */, D2A5E0CF19D3D6A90034B709 /* SDCAlertCollectionViewCell.h */, D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */, D2A6A0D919D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.h */, @@ -481,7 +481,7 @@ D25B3CDE17ECF1C5004B32A2 /* SDCAlertView.m in Sources */, D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */, D2A6A0DB19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m in Sources */, - D2666A4019CFDE2800167157 /* SDCAlertRepresentationView.m in Sources */, + D2666A4019CFDE2800167157 /* SDCAlertControllerView.m in Sources */, D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */, D263F1131829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m in Sources */, D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */, diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index cb22c78c..15e6ca7d 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -10,7 +10,7 @@ #import "SDCAlertTextFieldViewController.h" #import "SDCAlertTransition.h" -#import "SDCAlertRepresentationView.h" +#import "SDCAlertControllerView.h" #import "SDCAlertControllerDefaultVisualStyle.h" #import "SDCIntrinsicallySizedView.h" @@ -21,12 +21,12 @@ @interface SDCAlertAction (Private) @property (nonatomic, copy) void (^handler)(SDCAlertAction *); @end -@interface SDCAlertController () +@interface SDCAlertController () @property (nonatomic, strong) NSMutableArray *mutableActions; @property (nonatomic, strong) NSMutableArray *mutableTextFields; @property (nonatomic, strong) id transitioningDelegate; @property (nonatomic, strong) id visualStyle; -@property (nonatomic, strong) SDCAlertRepresentationView *alert; +@property (nonatomic, strong) SDCAlertControllerView *alert; @end @implementation SDCAlertController @@ -105,7 +105,7 @@ - (void)setMessage:(NSString *)message { - (void)createAlert { NSAttributedString *title = self.attributedTitle ? : [[NSAttributedString alloc] initWithString:self.title]; NSAttributedString *message = self.attributedMessage ? : [[NSAttributedString alloc] initWithString:self.message]; - self.alert = [[SDCAlertRepresentationView alloc] initWithTitle:title message:message]; + self.alert = [[SDCAlertControllerView alloc] initWithTitle:title message:message]; self.alert.delegate = self; self.alert.contentView = [[SDCIntrinsicallySizedView alloc] init]; @@ -125,7 +125,7 @@ - (void)viewDidLoad { [self.alert sdc_centerInSuperview]; } -- (void)showTextFieldsInAlertView:(SDCAlertRepresentationView *)alertView { +- (void)showTextFieldsInAlertView:(SDCAlertControllerView *)alertView { if (self.textFields.count > 0) { SDCAlertTextFieldViewController *textFieldViewController = [[SDCAlertTextFieldViewController alloc] init]; textFieldViewController.textFields = self.textFields; @@ -160,7 +160,7 @@ - (NSArray *)actions { return [self.mutableActions copy]; } -- (void)alertRepresentationView:(SDCAlertRepresentationView *)sender didPerformAction:(SDCAlertAction *)action { +- (void)alertControllerView:(SDCAlertControllerView *)sender didPerformAction:(SDCAlertAction *)action { if (!action.isEnabled || (self.shouldDismissBlock && !self.shouldDismissBlock(action))) { return; } diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.h b/SDCAlertView/Source/SDCAlertControllerView.h similarity index 70% rename from SDCAlertView/Source/SDCAlertRepresentationView.h rename to SDCAlertView/Source/SDCAlertControllerView.h index 96e6d6d5..cc6257f3 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.h +++ b/SDCAlertView/Source/SDCAlertControllerView.h @@ -1,5 +1,5 @@ // -// SDCAlertRepresentationView.h +// SDCAlertControllerView.h // SDCAlertView // // Created by Scott Berrevoets on 9/21/14. @@ -10,19 +10,19 @@ #import "SDCAlertController.h" // SDCAlertControllerButtonLayout -@class SDCAlertRepresentationView; +@class SDCAlertControllerView; @class SDCAlertAction; @class SDCAlertTextFieldViewController; -@protocol SDCAlertRepresentationViewDelegate -- (void)alertRepresentationView:(SDCAlertRepresentationView *)sender didPerformAction:(SDCAlertAction *)action; +@protocol SDCAlertControllerViewDelegate +- (void)alertControllerView:(SDCAlertControllerView *)sender didPerformAction:(SDCAlertAction *)action; @end @protocol SDCAlertControllerVisualStyle; -@interface SDCAlertRepresentationView : UIView +@interface SDCAlertControllerView : UIView -@property (nonatomic, weak) id delegate; +@property (nonatomic, weak) id delegate; @property (nonatomic, copy) NSAttributedString *title; @property (nonatomic, copy) NSAttributedString *message; diff --git a/SDCAlertView/Source/SDCAlertRepresentationView.m b/SDCAlertView/Source/SDCAlertControllerView.m similarity index 96% rename from SDCAlertView/Source/SDCAlertRepresentationView.m rename to SDCAlertView/Source/SDCAlertControllerView.m index fb595e24..e4dd17ed 100644 --- a/SDCAlertView/Source/SDCAlertRepresentationView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -1,12 +1,12 @@ // -// SDCAlertRepresentationView.m +// SDCAlertControllerView.m // SDCAlertView // // Created by Scott Berrevoets on 9/21/14. // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import "SDCAlertRepresentationView.h" +#import "SDCAlertControllerView.h" #import "SDCAlertController.h" #import "SDCAlertViewBackgroundView.h" @@ -19,14 +19,14 @@ static NSString *const SDCAlertControllerCellReuseIdentifier = @"SDCAlertControllerCellReuseIdentifier"; -@interface SDCAlertRepresentationView () +@interface SDCAlertControllerView () @property (nonatomic, strong) UIVisualEffectView *visualEffectView; @property (nonatomic, strong) SDCAlertScrollView *scrollView; @property (nonatomic, strong) UICollectionView *buttonCollectionView; @property (nonatomic, strong) SDCAlertControllerCollectionViewFlowLayout *collectionViewLayout; @end -@implementation SDCAlertRepresentationView +@implementation SDCAlertControllerView - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedString *)message { self = [self init]; @@ -161,7 +161,7 @@ - (void)actionButtonTapped:(UITapGestureRecognizer *)sender { NSIndexPath *indexPath = [self.buttonCollectionView indexPathForCell:cell]; SDCAlertAction *action = self.actions[indexPath.row]; - [self.delegate alertRepresentationView:self didPerformAction:action]; + [self.delegate alertControllerView:self didPerformAction:action]; } #pragma mark - UICollectionViewDelegate From 66944695a1cb4747f0f5acfce7e06962f6292f45 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 4 Oct 2014 19:24:22 -0700 Subject: [PATCH 40/76] Use "action" terminology, not "button" --- .../Source/SDCAlertCollectionViewCell.m | 6 +- SDCAlertView/Source/SDCAlertController.h | 10 +-- SDCAlertView/Source/SDCAlertController.m | 4 +- ...CAlertControllerCollectionViewFlowLayout.m | 6 +- .../SDCAlertControllerDefaultVisualStyle.m | 20 +++--- SDCAlertView/Source/SDCAlertControllerView.h | 4 +- SDCAlertView/Source/SDCAlertControllerView.m | 62 +++++++++---------- .../Source/SDCAlertControllerVisualStyle.h | 18 +++--- .../Source/SDCAlertPresentationController.m | 2 +- 9 files changed, 66 insertions(+), 66 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 35061bad..74d24c00 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -48,10 +48,10 @@ - (void)updateWithAction:(SDCAlertAction *)action visualStyle:(id @@ -48,7 +48,7 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerButtonLayout) { - (void)addAction:(SDCAlertAction *)action; @property (nonatomic, readonly) NSArray *actions; -@property (nonatomic) SDCAlertControllerButtonLayout buttonLayout; +@property (nonatomic) SDCAlertControllerActionLayout actionLayout; - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler; @property (nonatomic, readonly) NSArray *textFields; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 15e6ca7d..d4c837ad 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -53,7 +53,7 @@ - (instancetype)initWithStyle:(SDCAlertControllerStyle)style { _mutableTextFields = [NSMutableArray array]; _visualStyle = [[SDCAlertControllerDefaultVisualStyle alloc] init]; - _buttonLayout = SDCAlertControllerButtonLayoutAutomatic; + _actionLayout = SDCAlertControllerActionLayoutAutomatic; self.modalPresentationStyle = UIModalPresentationCustom; self.transitioningDelegate = [[SDCAlertTransitioningDelegate alloc] init]; @@ -117,7 +117,7 @@ - (void)viewDidLoad { self.alert.visualStyle = self.visualStyle; self.alert.actions = self.actions; - self.alert.buttonLayout = self.buttonLayout; + self.alert.actionLayout = self.actionLayout; [self showTextFieldsInAlertView:self.alert]; diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m index aebe0e8b..b5bf396e 100644 --- a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m @@ -54,13 +54,13 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(N UICollectionViewLayoutAttributes *itemAttributes = [self layoutAttributesForItemAtIndexPath:indexPath]; attributes.zIndex = itemAttributes.zIndex + 1; - attributes.backgroundColor = self.visualStyle.buttonSeparatorColor; + attributes.backgroundColor = self.visualStyle.actionViewSeparatorColor; CGRect decorationFrame = itemAttributes.frame; if (elementKind == SDCAlertControllerDecorationKindHorizontalSeparator) { - decorationFrame.size.height = self.visualStyle.buttonSeparatorThickness; + decorationFrame.size.height = self.visualStyle.actionViewSeparatorThickness; } else { - decorationFrame.size.width = self.visualStyle.buttonSeparatorThickness; + decorationFrame.size.width = self.visualStyle.actionViewSeparatorThickness; } attributes.frame = decorationFrame; diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index 0a787935..dd76cfe0 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -16,19 +16,19 @@ - (CGFloat)width { return 270; } -- (CGFloat)buttonHeight { +- (CGFloat)actionViewHeight { return 44; } -- (CGFloat)minimumButtonWidth { - return 90; // Fits exactly three buttons without scrolling +- (CGFloat)minimumActionViewWidth { + return 90; // Fits exactly three actions without scrolling } -- (CGFloat)buttonTopSpacingWithContentView { +- (CGFloat)actionViewTopSpacingWithContentView { return 0; } -- (CGFloat)buttonTopSpacingWithoutContentView { +- (CGFloat)actionViewTopSpacingWithoutContentView { return 20; } @@ -48,17 +48,17 @@ - (CGFloat)textFieldsTopSpacing { return 24; } -- (UIView *)buttonHighlightBackgroundView { +- (UIView *)actionViewHighlightBackgroundView { UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor colorWithWhite:.80 alpha:.7]; return view; } -- (UIColor *)buttonSeparatorColor { +- (UIColor *)actionViewSeparatorColor { return [UIColor colorWithWhite:0.5 alpha:0.5]; } -- (CGFloat)buttonSeparatorThickness { +- (CGFloat)actionViewSeparatorThickness { return 1 / [UIScreen mainScreen].scale; } @@ -74,7 +74,7 @@ - (UIFont *)textFieldFont { return [UIFont systemFontOfSize:13]; } -- (UIColor *)textColorForButtonRepresentingAction:(SDCAlertAction *)action { +- (UIColor *)textColorForAction:(SDCAlertAction *)action { if (action.style == SDCAlertActionStyleDestructive) { return [UIColor redColor]; } else { @@ -82,7 +82,7 @@ - (UIColor *)textColorForButtonRepresentingAction:(SDCAlertAction *)action { } } -- (UIFont *)fontForButtonRepresentingAction:(SDCAlertAction *)action { +- (UIFont *)fontForAction:(SDCAlertAction *)action { if (action.style == SDCAlertActionStyleCancel) { return [UIFont boldSystemFontOfSize:17]; } else { diff --git a/SDCAlertView/Source/SDCAlertControllerView.h b/SDCAlertView/Source/SDCAlertControllerView.h index cc6257f3..2cb5b5fe 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.h +++ b/SDCAlertView/Source/SDCAlertControllerView.h @@ -8,7 +8,7 @@ @import UIKit; -#import "SDCAlertController.h" // SDCAlertControllerButtonLayout +#import "SDCAlertController.h" // SDCAlertControllerActionLayout @class SDCAlertControllerView; @class SDCAlertAction; @@ -28,7 +28,7 @@ @property (nonatomic, copy) NSAttributedString *message; @property (nonatomic, copy) NSArray *actions; -@property (nonatomic) SDCAlertControllerButtonLayout buttonLayout; +@property (nonatomic) SDCAlertControllerActionLayout actionLayout; @property (nonatomic, strong) UIView *contentView; diff --git a/SDCAlertView/Source/SDCAlertControllerView.m b/SDCAlertView/Source/SDCAlertControllerView.m index e4dd17ed..affa54d6 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -22,7 +22,7 @@ @interface SDCAlertControllerView () @property (nonatomic, strong) UIVisualEffectView *visualEffectView; @property (nonatomic, strong) SDCAlertScrollView *scrollView; -@property (nonatomic, strong) UICollectionView *buttonCollectionView; +@property (nonatomic, strong) UICollectionView *actionsCollectionView; @property (nonatomic, strong) SDCAlertControllerCollectionViewFlowLayout *collectionViewLayout; @end @@ -44,13 +44,13 @@ - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedS [_collectionViewLayout registerClass:[SDCAlertControllerSeparatorView class] forDecorationViewOfKind:SDCAlertControllerDecorationKindHorizontalSeparator]; [_collectionViewLayout registerClass:[SDCAlertControllerSeparatorView class] forDecorationViewOfKind:SDCAlertControllerDecorationKindVerticalSeparator]; - _buttonCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_collectionViewLayout]; - [_buttonCollectionView setTranslatesAutoresizingMaskIntoConstraints:NO]; - [_buttonCollectionView registerClass:[SDCAlertCollectionViewCell class] forCellWithReuseIdentifier:SDCAlertControllerCellReuseIdentifier]; + _actionsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_collectionViewLayout]; + [_actionsCollectionView setTranslatesAutoresizingMaskIntoConstraints:NO]; + [_actionsCollectionView registerClass:[SDCAlertCollectionViewCell class] forCellWithReuseIdentifier:SDCAlertControllerCellReuseIdentifier]; - _buttonCollectionView.delegate = self; - _buttonCollectionView.dataSource = self; - _buttonCollectionView.backgroundColor = [UIColor clearColor]; + _actionsCollectionView.delegate = self; + _actionsCollectionView.dataSource = self; + _actionsCollectionView.backgroundColor = [UIColor clearColor]; [self setTranslatesAutoresizingMaskIntoConstraints:NO]; } @@ -74,12 +74,12 @@ - (void)setMessage:(NSAttributedString *)message { self.scrollView.message = message; } -- (void)setButtonLayout:(SDCAlertControllerButtonLayout)buttonLayout { - _buttonLayout = buttonLayout; +- (void)setActionLayout:(SDCAlertControllerActionLayout)actionLayout { + _actionLayout = actionLayout; UICollectionViewScrollDirection direction = UICollectionViewScrollDirectionHorizontal; - if (buttonLayout == SDCAlertControllerButtonLayoutVertical || (buttonLayout == SDCAlertControllerButtonLayoutAutomatic && self.actions.count != 2)) { + if (actionLayout == SDCAlertControllerActionLayoutVertical || (actionLayout == SDCAlertControllerActionLayoutAutomatic && self.actions.count != 2)) { direction = UICollectionViewScrollDirectionVertical; } @@ -95,23 +95,23 @@ - (CGFloat)maximumHeightForScrollView { if (self.actions.count > 0) { if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) { - maximumHeight -= self.visualStyle.buttonHeight; + maximumHeight -= self.visualStyle.actionViewHeight; } else { - maximumHeight -= self.visualStyle.buttonHeight * [self.buttonCollectionView numberOfItemsInSection:0]; + maximumHeight -= self.visualStyle.actionViewHeight * [self.actionsCollectionView numberOfItemsInSection:0]; } } return maximumHeight; } -- (CGFloat)heightForButtonCollectionView { - CGFloat horizontalLayoutHeight = self.visualStyle.buttonHeight; - CGFloat verticalLayoutHeight = self.visualStyle.buttonHeight * [self.buttonCollectionView numberOfItemsInSection:0]; +- (CGFloat)collectionViewHeight { + CGFloat horizontalLayoutHeight = self.visualStyle.actionViewHeight; + CGFloat verticalLayoutHeight = self.visualStyle.actionViewHeight * [self.actionsCollectionView numberOfItemsInSection:0]; - switch (self.buttonLayout) { - case SDCAlertControllerButtonLayoutAutomatic: return (self.actions.count == 2) ? horizontalLayoutHeight : verticalLayoutHeight; - case SDCAlertControllerButtonLayoutHorizontal: return horizontalLayoutHeight; - case SDCAlertControllerButtonLayoutVertical: return verticalLayoutHeight; + switch (self.actionLayout) { + case SDCAlertControllerActionLayoutAutomatic: return (self.actions.count == 2) ? horizontalLayoutHeight : verticalLayoutHeight; + case SDCAlertControllerActionLayoutHorizontal: return horizontalLayoutHeight; + case SDCAlertControllerActionLayoutVertical: return verticalLayoutHeight; } } @@ -131,21 +131,21 @@ - (void)layoutSubviews { self.scrollView.contentSize = CGSizeMake(self.visualStyle.width, [self.scrollView intrinsicContentSize].height); UIView *aligningView = self.scrollView; - CGFloat buttonTopSpacing = self.visualStyle.buttonTopSpacingWithoutContentView; + CGFloat actionViewTopSpacing = self.visualStyle.actionViewTopSpacingWithoutContentView; if (self.contentView.subviews.count > 0) { aligningView = self.contentView; - buttonTopSpacing = self.visualStyle.buttonTopSpacingWithContentView; + actionViewTopSpacing = self.visualStyle.actionViewTopSpacingWithContentView; [self.visualEffectView.contentView addSubview:self.contentView]; [self.contentView sdc_alignEdges:UIRectEdgeLeft|UIRectEdgeRight withView:self.scrollView]; [self.contentView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:self.scrollView]; } - [self.visualEffectView.contentView addSubview:self.buttonCollectionView]; - [self.buttonCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:aligningView inset:buttonTopSpacing]; - [self.buttonCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]; - [self.buttonCollectionView sdc_pinHeight:[self heightForButtonCollectionView]]; + [self.visualEffectView.contentView addSubview:self.actionsCollectionView]; + [self.actionsCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:aligningView inset:actionViewTopSpacing]; + [self.actionsCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]; + [self.actionsCollectionView sdc_pinHeight:[self collectionViewHeight]]; [self addSubview:self.visualEffectView]; [self.visualEffectView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; @@ -156,9 +156,9 @@ - (void)applyCurrentStyleToAlertElements { self.collectionViewLayout.visualStyle = self.visualStyle; } -- (void)actionButtonTapped:(UITapGestureRecognizer *)sender { +- (void)actionViewTapped:(UITapGestureRecognizer *)sender { SDCAlertCollectionViewCell *cell = (SDCAlertCollectionViewCell *)sender.view; - NSIndexPath *indexPath = [self.buttonCollectionView indexPathForCell:cell]; + NSIndexPath *indexPath = [self.actionsCollectionView indexPathForCell:cell]; SDCAlertAction *action = self.actions[indexPath.row]; [self.delegate alertControllerView:self didPerformAction:action]; @@ -176,7 +176,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell SDCAlertAction *action = self.actions[indexPath.item]; [cell updateWithAction:action visualStyle:self.visualStyle]; - cell.gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionButtonTapped:)]; + cell.gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionViewTapped:)]; return cell; } @@ -184,10 +184,10 @@ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionVertical) { - return CGSizeMake(CGRectGetWidth(self.bounds), self.visualStyle.buttonHeight); + return CGSizeMake(CGRectGetWidth(self.bounds), self.visualStyle.actionViewHeight); } else { - CGFloat width = MAX(CGRectGetWidth(self.bounds) / self.actions.count, self.visualStyle.minimumButtonWidth); - return CGSizeMake(width, self.visualStyle.buttonHeight); + CGFloat width = MAX(CGRectGetWidth(self.bounds) / self.actions.count, self.visualStyle.minimumActionViewWidth); + return CGSizeMake(width, self.visualStyle.actionViewHeight); } } diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index 111d2ecc..1d87a6fa 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -13,25 +13,25 @@ @protocol SDCAlertControllerVisualStyle @property (nonatomic, readonly) CGFloat width; -@property (nonatomic, readonly) CGFloat buttonHeight; -@property (nonatomic, readonly) CGFloat buttonTopSpacingWithContentView; -@property (nonatomic, readonly) CGFloat buttonTopSpacingWithoutContentView; -@property (nonatomic, readonly) CGFloat minimumButtonWidth; // For forced horizontal layout and 3+ buttons +@property (nonatomic, readonly) CGFloat actionViewHeight; +@property (nonatomic, readonly) CGFloat actionViewTopSpacingWithContentView; +@property (nonatomic, readonly) CGFloat actionViewTopSpacingWithoutContentView; +@property (nonatomic, readonly) CGFloat minimumActionViewWidth; // For forced horizontal layout and 3+ buttons @property (nonatomic, readonly) UIEdgeInsets margins; @property (nonatomic, readonly) UIEdgeInsets contentPadding; @property (nonatomic, readonly) CGFloat labelSpacing; @property (nonatomic, readonly) CGFloat textFieldsTopSpacing; -@property (nonatomic, readonly) UIView *buttonHighlightBackgroundView; -@property (nonatomic, readonly) UIColor *buttonSeparatorColor; -@property (nonatomic, readonly) CGFloat buttonSeparatorThickness; +@property (nonatomic, readonly) UIView *actionViewHighlightBackgroundView; +@property (nonatomic, readonly) UIColor *actionViewSeparatorColor; +@property (nonatomic, readonly) CGFloat actionViewSeparatorThickness; @property (nonatomic, readonly) UIFont *titleLabelFont; @property (nonatomic, readonly) UIFont *messageLabelFont; @property (nonatomic, readonly) UIFont *textFieldFont; -- (UIColor *)textColorForButtonRepresentingAction:(SDCAlertAction *)action; -- (UIFont *)fontForButtonRepresentingAction:(SDCAlertAction *)action; +- (UIColor *)textColorForAction:(SDCAlertAction *)action; +- (UIFont *)fontForAction:(SDCAlertAction *)action; @end diff --git a/SDCAlertView/Source/SDCAlertPresentationController.m b/SDCAlertView/Source/SDCAlertPresentationController.m index 550b4491..f9fd34ea 100644 --- a/SDCAlertView/Source/SDCAlertPresentationController.m +++ b/SDCAlertView/Source/SDCAlertPresentationController.m @@ -50,7 +50,7 @@ - (void)dismissalTransitionWillBegin { - (void)containerViewWillLayoutSubviews { [super containerViewWillLayoutSubviews]; - + self.dimmingView.frame = self.containerView.frame; } From 907087c38acb27398b5657c123957c0bb0dd1b59 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 4 Oct 2014 19:25:48 -0700 Subject: [PATCH 41/76] Use @import instead of #import <> --- SDCAlertView/Source/SDCAlertCollectionViewCell.h | 2 +- SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.h | 2 +- SDCAlertView/Source/SDCAlertLabel.h | 2 +- SDCAlertView/Source/SDCAlertPresentationController.h | 2 +- SDCAlertView/Source/SDCAlertTransition.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.h b/SDCAlertView/Source/SDCAlertCollectionViewCell.h index 3b3f1d09..b7b8378a 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.h +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.h @@ -6,7 +6,7 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; @class SDCAlertAction; @protocol SDCAlertControllerVisualStyle; diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.h index a56665e1..9504eaf8 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.h @@ -6,7 +6,7 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import Foundation; #import "SDCAlertControllerVisualStyle.h" diff --git a/SDCAlertView/Source/SDCAlertLabel.h b/SDCAlertView/Source/SDCAlertLabel.h index efa5de2b..da06d737 100644 --- a/SDCAlertView/Source/SDCAlertLabel.h +++ b/SDCAlertView/Source/SDCAlertLabel.h @@ -6,7 +6,7 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; @interface SDCAlertLabel : UILabel diff --git a/SDCAlertView/Source/SDCAlertPresentationController.h b/SDCAlertView/Source/SDCAlertPresentationController.h index e2a42587..5b9a293e 100644 --- a/SDCAlertView/Source/SDCAlertPresentationController.h +++ b/SDCAlertView/Source/SDCAlertPresentationController.h @@ -6,7 +6,7 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; @interface SDCAlertPresentationController : UIPresentationController diff --git a/SDCAlertView/Source/SDCAlertTransition.h b/SDCAlertView/Source/SDCAlertTransition.h index 65caa7b0..e1c28041 100644 --- a/SDCAlertView/Source/SDCAlertTransition.h +++ b/SDCAlertView/Source/SDCAlertTransition.h @@ -6,7 +6,7 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import Foundation; @interface SDCAlertAnimationController : NSObject @property (nonatomic, getter=isPresentation) BOOL presentation; From 112363236c6589f83d446447f890c9e862ca690d Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 4 Oct 2014 20:08:35 -0700 Subject: [PATCH 42/76] Use visual style for text field appearance --- SDCAlertView/SDCViewController.m | 5 +-- SDCAlertView/Source/SDCAlertController.m | 5 +-- .../SDCAlertControllerDefaultVisualStyle.m | 16 +++++++ .../Source/SDCAlertControllerVisualStyle.h | 5 +++ SDCAlertView/Source/SDCAlertScrollView.m | 3 +- .../Source/SDCAlertTextFieldTableViewCell.h | 5 +++ .../Source/SDCAlertTextFieldTableViewCell.m | 15 +++++-- .../Source/SDCAlertTextFieldViewController.h | 4 +- .../Source/SDCAlertTextFieldViewController.m | 44 +++++++++++++++---- 9 files changed, 81 insertions(+), 21 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index a270da0e..a141396f 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -44,7 +44,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath NSLog(@"%@", action.title); }]]; -// [ac addTextFieldWithConfigurationHandler:nil]; + [ac addTextFieldWithConfigurationHandler:nil]; // [ac addTextFieldWithConfigurationHandler:nil]; UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; @@ -65,9 +65,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath //[SDCAlertController showAlertControllerWithTitle:@"Title" message:@"Message" actionTitle:@"OK"]; [ac presentWithCompletion:^{ - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [ac dismiss]; - }); }]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index d4c837ad..be46c8f0 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -127,9 +127,8 @@ - (void)viewDidLoad { - (void)showTextFieldsInAlertView:(SDCAlertControllerView *)alertView { if (self.textFields.count > 0) { - SDCAlertTextFieldViewController *textFieldViewController = [[SDCAlertTextFieldViewController alloc] init]; - textFieldViewController.textFields = self.textFields; - + SDCAlertTextFieldViewController *textFieldViewController = [[SDCAlertTextFieldViewController alloc] initWithTextFields:self.textFields + visualStyle:self.visualStyle]; [self addChildViewController:textFieldViewController]; [alertView showTextFieldViewController:textFieldViewController]; [textFieldViewController didMoveToParentViewController:self]; diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index dd76cfe0..18ca683a 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -44,10 +44,26 @@ - (CGFloat)labelSpacing { return 18; } +- (CGFloat)estimatedTextFieldHeight { + return 25; +} + - (CGFloat)textFieldsTopSpacing { return 24; } +- (CGFloat)textFieldBorderWidth { + return 1 / [UIScreen mainScreen].scale; +} + +- (UIColor *)textFieldBorderColor { + return [UIColor colorWithRed:64.f/255 green:64.f/255 blue:64.f/255 alpha:1]; +} + +- (UIEdgeInsets)textFieldMargins { + return UIEdgeInsetsMake(4, 4, 4, 4); +} + - (UIView *)actionViewHighlightBackgroundView { UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor colorWithWhite:.80 alpha:.7]; diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index 1d87a6fa..bf2083a8 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -21,7 +21,12 @@ @property (nonatomic, readonly) UIEdgeInsets margins; @property (nonatomic, readonly) UIEdgeInsets contentPadding; @property (nonatomic, readonly) CGFloat labelSpacing; + +@property (nonatomic, readonly) CGFloat estimatedTextFieldHeight; @property (nonatomic, readonly) CGFloat textFieldsTopSpacing; +@property (nonatomic, readonly) CGFloat textFieldBorderWidth; +@property (nonatomic, readonly) UIColor *textFieldBorderColor; +@property (nonatomic, readonly) UIEdgeInsets textFieldMargins; @property (nonatomic, readonly) UIView *actionViewHighlightBackgroundView; @property (nonatomic, readonly) UIColor *actionViewSeparatorColor; diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index d64d926d..8d2f1c49 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -97,8 +97,7 @@ - (void)layoutSubviews { if (self.textFieldViewController) { [self.textFieldViewController.view sdc_alignEdges:UIRectEdgeLeft|UIRectEdgeRight withView:self.titleLabel]; - // Could use self.textFieldViewController.tableView to calculate height, but it being a UITableViewController subclass is an implementation detail. - CGFloat height = [self.textFieldViewController requiredHeightForDisplayingAllTextFields] + self.visualStyle.contentPadding.bottom; + CGFloat height = self.textFieldViewController.requiredHeightForDisplayingAllTextFields + self.visualStyle.contentPadding.bottom; [self.textFieldViewController.view sdc_pinHeight:height]; [self addConstraint:[NSLayoutConstraint constraintWithItem:self.textFieldViewController.view diff --git a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.h b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.h index 6a155625..b2e9164b 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.h +++ b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.h @@ -8,8 +8,13 @@ @import UIKit; +@protocol SDCAlertControllerVisualStyle; + @interface SDCAlertTextFieldTableViewCell : UITableViewCell +@property (nonatomic, strong) id visualStyle; // Apply a visual style before setting the text field @property (nonatomic, strong) UITextField *textField; +@property (nonatomic, readonly) CGFloat requiredHeight; + @end diff --git a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m index d282c0de..51229c3c 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m +++ b/SDCAlertView/Source/SDCAlertTextFieldTableViewCell.m @@ -8,6 +8,8 @@ #import "SDCAlertTextFieldTableViewCell.h" +#import "SDCAlertControllerVisualStyle.h" + #import "UIView+SDCAutoLayout.h" @implementation SDCAlertTextFieldTableViewCell @@ -17,8 +19,9 @@ - (void)setTextField:(UITextField *)textField { [textField setTranslatesAutoresizingMaskIntoConstraints:NO]; UIView *borderView = [[UIView alloc] init]; + borderView.backgroundColor = self.visualStyle.textFieldBorderColor; [borderView setTranslatesAutoresizingMaskIntoConstraints:NO]; - borderView.backgroundColor = [UIColor colorWithRed:64.f/255 green:64.f/255 blue:64.f/255 alpha:1]; + [borderView sdc_pinHeight:self.requiredHeight]; [self.contentView addSubview:borderView]; [borderView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; @@ -28,12 +31,18 @@ - (void)setTextField:(UITextField *)textField { [textFieldView setTranslatesAutoresizingMaskIntoConstraints:NO]; [borderView addSubview:textFieldView]; - [textFieldView sdc_alignEdgesWithSuperview:UIRectEdgeAll insets:UIEdgeInsetsMake(0.5, 0.5, -0.5, -0.5)]; + + CGFloat borderWidth = self.visualStyle.textFieldBorderWidth; + [textFieldView sdc_alignEdgesWithSuperview:UIRectEdgeAll insets:UIEdgeInsetsMake(borderWidth, borderWidth, -borderWidth, -borderWidth)]; [textFieldView sdc_centerInSuperview]; [textFieldView addSubview:textField]; [textField sdc_centerInSuperview]; - [textField sdc_pinWidthToWidthOfView:textFieldView offset:-8]; + [textField sdc_pinWidthToWidthOfView:textFieldView offset:-(self.visualStyle.textFieldMargins.left + self.visualStyle.textFieldMargins.right)]; +} + +- (CGFloat)requiredHeight { + return [self.textField intrinsicContentSize].height + self.visualStyle.textFieldMargins.top + self.visualStyle.textFieldMargins.bottom; } @end diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.h b/SDCAlertView/Source/SDCAlertTextFieldViewController.h index fc447ee1..324a10a3 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.h +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.h @@ -8,9 +8,11 @@ @import UIKit; +@protocol SDCAlertControllerVisualStyle; + @interface SDCAlertTextFieldViewController : UITableViewController -@property (nonatomic, strong) NSArray *textFields; +- (instancetype)initWithTextFields:(NSArray *)textFields visualStyle:(id)visualStyle; - (CGFloat)requiredHeightForDisplayingAllTextFields; diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.m b/SDCAlertView/Source/SDCAlertTextFieldViewController.m index 6f27e7f1..af52b1be 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.m +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.m @@ -8,20 +8,39 @@ #import "SDCAlertTextFieldViewController.h" +#import "SDCAlertControllerVisualStyle.h" #import "SDCAlertTextFieldTableViewCell.h" static NSString *const SDCAlertTextFieldCellIdentifier = @"SDCAlertTextFieldCellIdentifier"; +@interface SDCAlertTextFieldViewController () +@property (nonatomic, strong) NSArray *textFields; +@property (nonatomic, strong) id visualStyle; +@end + @implementation SDCAlertTextFieldViewController -- (void)viewDidLoad { - [super viewDidLoad]; - [self.tableView registerClass:[SDCAlertTextFieldTableViewCell class] forCellReuseIdentifier:SDCAlertTextFieldCellIdentifier]; +- (instancetype)initWithTextFields:(NSArray *)textFields visualStyle:(id)visualStyle { + self = [self init]; + + if (self) { + _textFields = textFields; + _visualStyle = visualStyle; + + [self.tableView registerClass:[SDCAlertTextFieldTableViewCell class] forCellReuseIdentifier:SDCAlertTextFieldCellIdentifier]; + + + self.tableView.scrollEnabled = NO; + self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; + self.tableView.backgroundColor = [UIColor clearColor]; + + self.tableView.estimatedRowHeight = visualStyle.estimatedTextFieldHeight; + + [self.tableView setNeedsLayout]; + [self.tableView layoutIfNeeded]; + } - self.tableView.rowHeight = 25; - self.tableView.scrollEnabled = NO; - self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; - self.tableView.backgroundColor = [UIColor clearColor]; + return self; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { @@ -31,6 +50,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SDCAlertTextFieldTableViewCell *textFieldCell = [tableView dequeueReusableCellWithIdentifier:SDCAlertTextFieldCellIdentifier forIndexPath:indexPath]; + textFieldCell.visualStyle = self.visualStyle; textFieldCell.textField = self.textFields[indexPath.row]; return textFieldCell; } @@ -40,7 +60,15 @@ - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSInde } - (CGFloat)requiredHeightForDisplayingAllTextFields { - return self.tableView.rowHeight * [self.tableView numberOfRowsInSection:0]; + CGFloat totalHeight = 0; + + for (NSUInteger i = 0; i < self.textFields.count; i++) { + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0]; + SDCAlertTextFieldTableViewCell *cell = (SDCAlertTextFieldTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath]; + totalHeight += cell.requiredHeight; + } + + return totalHeight; } @end From a37c6c0a10e89e68f31956442dcd378fed212705 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sat, 4 Oct 2014 23:55:57 -0700 Subject: [PATCH 43/76] Make alert reposition based on keyboard presence --- SDCAlertView/SDCViewController.m | 18 ++++++++++++------ SDCAlertView/Source/SDCAlertController.m | 19 +++++++++++++++++++ .../Source/SDCAlertTextFieldViewController.m | 3 ++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index a141396f..e2fe3372 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -16,7 +16,7 @@ #import "SDCAlertController.h" #import "SDCAlertTransition.h" -@interface SDCViewController () +@interface SDCViewController () @end @implementation SDCViewController @@ -29,7 +29,7 @@ - (void)presentNow { [b addAction:[UIAlertAction actionWithTitle:@"Button 33??" style:UIAlertActionStyleCancel handler:nil]]; [b addTextFieldWithConfigurationHandler:nil]; - [b addTextFieldWithConfigurationHandler:nil]; + //[b addTextFieldWithConfigurationHandler:nil]; [self presentViewController:b animated:YES completion:^{ // b.title = nil; @@ -44,7 +44,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath NSLog(@"%@", action.title); }]]; - [ac addTextFieldWithConfigurationHandler:nil]; + [ac addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.delegate = self; + }]; // [ac addTextFieldWithConfigurationHandler:nil]; UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; @@ -64,9 +66,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath //[SDCAlertController showAlertControllerWithTitle:@"Title" message:@"Message" actionTitle:@"OK"]; - [ac presentWithCompletion:^{ - }]; - // [self presentNow]; + [ac presentWithCompletion:nil]; +// [self presentNow]; } else if (indexPath.section == 1) { if (indexPath.row == 0) { @@ -166,6 +167,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [tableView deselectRowAtIndexPath:indexPath animated:YES]; } +- (BOOL)textFieldShouldReturn:(UITextField *)textField { + [textField resignFirstResponder]; + return YES; +} + - (void)updateProgressView:(NSTimer *)timer { UIProgressView *progressView = [timer userInfo]; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index be46c8f0..252f0311 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -57,6 +57,8 @@ - (instancetype)initWithStyle:(SDCAlertControllerStyle)style { self.modalPresentationStyle = UIModalPresentationCustom; self.transitioningDelegate = [[SDCAlertTransitioningDelegate alloc] init]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardUpdate:) name:UIKeyboardWillChangeFrameNotification object:nil]; } return self; @@ -100,6 +102,10 @@ - (void)setMessage:(NSString *)message { self.alert.message = [[NSAttributedString alloc] initWithString:message]; } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + #pragma mark - Alert View - (void)createAlert { @@ -176,6 +182,7 @@ - (void)alertControllerView:(SDCAlertControllerView *)sender didPerformAction:(S - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *))configurationHandler { UITextField *textField = [[UITextField alloc] init]; textField.font = self.visualStyle.textFieldFont; + textField.autocorrectionType = UITextAutocorrectionTypeNo; [self.mutableTextFields addObject:textField]; if (configurationHandler) { @@ -187,6 +194,18 @@ - (NSArray *)textFields { return [self.mutableTextFields copy]; } +- (void)keyboardUpdate:(NSNotification *)notification { + NSValue *frameValue = notification.userInfo[UIKeyboardFrameEndUserInfoKey]; + CGRect frame = [frameValue CGRectValue]; + + NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; + UIViewAnimationOptions curve = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16; + + [UIView animateWithDuration:duration delay:0 options:curve animations:^{ + self.view.frame = CGRectMake(0, 0, 320, CGRectGetMinY(frame)); + } completion:nil]; +} + @end @implementation SDCAlertController (Presentation) diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.m b/SDCAlertView/Source/SDCAlertTextFieldViewController.m index af52b1be..c41b1bf2 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.m +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.m @@ -29,7 +29,6 @@ - (instancetype)initWithTextFields:(NSArray *)textFields visualStyle:(id Date: Sun, 5 Oct 2014 00:33:09 -0700 Subject: [PATCH 44/76] Correctly adjust alert when rotating device --- SDCAlertView/SDCViewController.m | 24 ++------------- SDCAlertView/Source/SDCAlertController.m | 13 ++++++++ SDCAlertView/Source/SDCAlertControllerView.h | 2 +- SDCAlertView/Source/SDCAlertControllerView.m | 30 ++++++++++++------- .../Source/SDCAlertTextFieldViewController.m | 2 -- 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index e2fe3372..4b3f7774 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -44,28 +44,10 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath NSLog(@"%@", action.title); }]]; - [ac addTextFieldWithConfigurationHandler:^(UITextField *textField) { - textField.delegate = self; - }]; -// [ac addTextFieldWithConfigurationHandler:nil]; - - UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; - progressView.progress = 0; - - [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateProgressView:) userInfo:progressView repeats:YES]; - - [progressView setTranslatesAutoresizingMaskIntoConstraints:NO]; - [ac.contentView addSubview:progressView]; - - [progressView sdc_pinWidthToWidthOfView:ac.contentView offset:-20]; - [progressView sdc_horizontallyCenterInSuperview]; - [ac.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(==20)-[progressView]-(==20)-|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(progressView)]]; - + [ac addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.delegate = self; + }]; - //[SDCAlertController showAlertControllerWithTitle:@"Title" message:@"Message" actionTitle:@"OK"]; [ac presentWithCompletion:nil]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 252f0311..3156a5f0 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -129,6 +129,19 @@ - (void)viewDidLoad { [self.view addSubview:self.alert]; [self.alert sdc_centerInSuperview]; + + [self.alert createViewHierarchy]; +} + +- (void)viewDidLayoutSubviews { + [super viewDidLayoutSubviews]; + + // Explanation of why the first responder is set here: + // http://stackoverflow.com/questions/1132784/iphone-have-the-keyboard-slide-into-view-from-the-right-like-when-editing-a-no + + if (![self.textFields.firstObject isFirstResponder]) { + [self.textFields.firstObject becomeFirstResponder]; + } } - (void)showTextFieldsInAlertView:(SDCAlertControllerView *)alertView { diff --git a/SDCAlertView/Source/SDCAlertControllerView.h b/SDCAlertView/Source/SDCAlertControllerView.h index 2cb5b5fe..05821560 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.h +++ b/SDCAlertView/Source/SDCAlertControllerView.h @@ -37,5 +37,5 @@ - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedString *)message; - (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController; - +- (void)createViewHierarchy; @end diff --git a/SDCAlertView/Source/SDCAlertControllerView.m b/SDCAlertView/Source/SDCAlertControllerView.m index affa54d6..9c338062 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -24,6 +24,7 @@ @interface SDCAlertControllerView () 0) { if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) { @@ -104,6 +105,14 @@ - (CGFloat)maximumHeightForScrollView { return maximumHeight; } +- (CGFloat)actionViewTopSpacing { + if (self.contentView.subviews.count > 0) { + return self.visualStyle.actionViewTopSpacingWithContentView; + } else { + return self.visualStyle.actionViewTopSpacingWithoutContentView; + } +} + - (CGFloat)collectionViewHeight { CGFloat horizontalLayoutHeight = self.visualStyle.actionViewHeight; CGFloat verticalLayoutHeight = self.visualStyle.actionViewHeight * [self.actionsCollectionView numberOfItemsInSection:0]; @@ -115,9 +124,7 @@ - (CGFloat)collectionViewHeight { } } -- (void)layoutSubviews { - [super layoutSubviews]; - +- (void)createViewHierarchy { [self applyCurrentStyleToAlertElements]; [self.visualEffectView sdc_pinWidth:self.visualStyle.width]; @@ -127,15 +134,12 @@ - (void)layoutSubviews { [self.scrollView layoutIfNeeded]; [self.scrollView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeTop|UIRectEdgeRight]; - [self.scrollView sdc_setMaximumHeight:[self maximumHeightForScrollView]]; - self.scrollView.contentSize = CGSizeMake(self.visualStyle.width, [self.scrollView intrinsicContentSize].height); + self.maximumHeightConstraint = [self.scrollView sdc_setMaximumHeight:[self maximumHeightForScrollView]]; UIView *aligningView = self.scrollView; - CGFloat actionViewTopSpacing = self.visualStyle.actionViewTopSpacingWithoutContentView; if (self.contentView.subviews.count > 0) { aligningView = self.contentView; - actionViewTopSpacing = self.visualStyle.actionViewTopSpacingWithContentView; [self.visualEffectView.contentView addSubview:self.contentView]; [self.contentView sdc_alignEdges:UIRectEdgeLeft|UIRectEdgeRight withView:self.scrollView]; @@ -143,7 +147,7 @@ - (void)layoutSubviews { } [self.visualEffectView.contentView addSubview:self.actionsCollectionView]; - [self.actionsCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:aligningView inset:actionViewTopSpacing]; + [self.actionsCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:aligningView inset:[self actionViewTopSpacing]]; [self.actionsCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]; [self.actionsCollectionView sdc_pinHeight:[self collectionViewHeight]]; @@ -151,6 +155,12 @@ - (void)layoutSubviews { [self.visualEffectView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; } +- (void)layoutSubviews { + [super layoutSubviews]; + self.maximumHeightConstraint.constant = [self maximumHeightForScrollView]; + self.scrollView.contentSize = CGSizeMake(self.visualStyle.width, [self.scrollView intrinsicContentSize].height); +} + - (void)applyCurrentStyleToAlertElements { self.scrollView.visualStyle = self.visualStyle; self.collectionViewLayout.visualStyle = self.visualStyle; @@ -181,7 +191,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell } - (CGSize)collectionView:(UICollectionView *)collectionView -layout:(UICollectionViewLayout *)collectionViewLayout + layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionVertical) { return CGSizeMake(CGRectGetWidth(self.bounds), self.visualStyle.actionViewHeight); diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.m b/SDCAlertView/Source/SDCAlertTextFieldViewController.m index c41b1bf2..426abfa8 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.m +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.m @@ -37,8 +37,6 @@ - (instancetype)initWithTextFields:(NSArray *)textFields visualStyle:(id Date: Sun, 5 Oct 2014 00:41:30 -0700 Subject: [PATCH 45/76] Use actual view width instead of wrong hardcoded value --- SDCAlertView/Source/SDCAlertController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 3156a5f0..9b2e75bf 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -215,7 +215,7 @@ - (void)keyboardUpdate:(NSNotification *)notification { UIViewAnimationOptions curve = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16; [UIView animateWithDuration:duration delay:0 options:curve animations:^{ - self.view.frame = CGRectMake(0, 0, 320, CGRectGetMinY(frame)); + self.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetMinY(frame)); } completion:nil]; } From 19740b4310069c4ded21f4201abec5aaf3ea3fe0 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 00:49:44 -0700 Subject: [PATCH 46/76] Update scroll view contentSize upon device rotation --- SDCAlertView/Source/SDCAlertControllerView.m | 1 - SDCAlertView/Source/SDCAlertScrollView.m | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/SDCAlertView/Source/SDCAlertControllerView.m b/SDCAlertView/Source/SDCAlertControllerView.m index 9c338062..8108b8b4 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -158,7 +158,6 @@ - (void)createViewHierarchy { - (void)layoutSubviews { [super layoutSubviews]; self.maximumHeightConstraint.constant = [self maximumHeightForScrollView]; - self.scrollView.contentSize = CGSizeMake(self.visualStyle.width, [self.scrollView intrinsicContentSize].height); } - (void)applyCurrentStyleToAlertElements { diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertScrollView.m index 8d2f1c49..0a87b357 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertScrollView.m @@ -112,6 +112,11 @@ - (void)layoutSubviews { [self invalidateIntrinsicContentSize]; } +- (void)invalidateIntrinsicContentSize { + [super invalidateIntrinsicContentSize]; + self.contentSize = CGSizeMake(self.contentSize.width, [self intrinsicContentSize].height); +} + - (CGSize)intrinsicContentSize { UIView *lastView = (self.textFieldViewController) ? self.textFieldViewController.view : self.messageLabel; CGFloat intrinsicHeight = CGRectGetMaxY(lastView.frame); From a12c6d8077049484d1f4604ca14689c8d01292f9 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 00:55:11 -0700 Subject: [PATCH 47/76] Avoid being unable to resign first responder Previously, resignFirstResponder caused a layout pass, which trigger viewDidLayoutSubviews. Since that method makes the text field the first responder if it isn't already, the text field would immediately become first responder again. This explicit flag avoids that. --- SDCAlertView/Source/SDCAlertController.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 9b2e75bf..0d26c7a6 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -27,6 +27,7 @@ @interface SDCAlertController () @property (nonatomic, strong) id transitioningDelegate; @property (nonatomic, strong) id visualStyle; @property (nonatomic, strong) SDCAlertControllerView *alert; +@property (nonatomic) BOOL didAssignFirstResponder; @end @implementation SDCAlertController @@ -139,8 +140,9 @@ - (void)viewDidLayoutSubviews { // Explanation of why the first responder is set here: // http://stackoverflow.com/questions/1132784/iphone-have-the-keyboard-slide-into-view-from-the-right-like-when-editing-a-no - if (![self.textFields.firstObject isFirstResponder]) { + if (!self.didAssignFirstResponder) { [self.textFields.firstObject becomeFirstResponder]; + self.didAssignFirstResponder = YES; } } From b1165710f34e3fd38ffe226819633916b4a2d50f Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 01:10:31 -0700 Subject: [PATCH 48/76] Avoid weird initial animation for alerts with text field --- SDCAlertView/Source/SDCAlertController.m | 55 ++++++++++++++---------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 0d26c7a6..d09b1d36 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -28,6 +28,7 @@ @interface SDCAlertController () @property (nonatomic, strong) id visualStyle; @property (nonatomic, strong) SDCAlertControllerView *alert; @property (nonatomic) BOOL didAssignFirstResponder; +@property (nonatomic, getter=isPresentingAlert) BOOL presentingAlert; @end @implementation SDCAlertController @@ -92,6 +93,11 @@ - (instancetype)initWithAttributedTitle:(NSAttributedString *)attributedTitle return self; } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +#pragma mark - Alert View - (void)setTitle:(NSString *)title { [super setTitle:title]; @@ -103,11 +109,6 @@ - (void)setMessage:(NSString *)message { self.alert.message = [[NSAttributedString alloc] initWithString:message]; } -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - -#pragma mark - Alert View - (void)createAlert { NSAttributedString *title = self.attributedTitle ? : [[NSAttributedString alloc] initWithString:self.title]; @@ -119,6 +120,22 @@ - (void)createAlert { [self.alert.contentView setTranslatesAutoresizingMaskIntoConstraints:NO]; } +- (void)showTextFieldsInAlertView:(SDCAlertControllerView *)alertView { + if (self.textFields.count > 0) { + SDCAlertTextFieldViewController *textFieldViewController = [[SDCAlertTextFieldViewController alloc] initWithTextFields:self.textFields + visualStyle:self.visualStyle]; + [self addChildViewController:textFieldViewController]; + [alertView showTextFieldViewController:textFieldViewController]; + [textFieldViewController didMoveToParentViewController:self]; + } +} + +- (UIView *)contentView { + return self.alert.contentView; +} + +#pragma mark - Lifecycle + - (void)viewDidLoad { [super viewDidLoad]; @@ -128,6 +145,8 @@ - (void)viewDidLoad { [self showTextFieldsInAlertView:self.alert]; + self.presentingAlert = YES; + [self.view addSubview:self.alert]; [self.alert sdc_centerInSuperview]; @@ -146,18 +165,9 @@ - (void)viewDidLayoutSubviews { } } -- (void)showTextFieldsInAlertView:(SDCAlertControllerView *)alertView { - if (self.textFields.count > 0) { - SDCAlertTextFieldViewController *textFieldViewController = [[SDCAlertTextFieldViewController alloc] initWithTextFields:self.textFields - visualStyle:self.visualStyle]; - [self addChildViewController:textFieldViewController]; - [alertView showTextFieldViewController:textFieldViewController]; - [textFieldViewController didMoveToParentViewController:self]; - } -} - -- (UIView *)contentView { - return self.alert.contentView; +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + self.presentingAlert = NO; } #pragma mark - Style @@ -213,12 +223,13 @@ - (void)keyboardUpdate:(NSNotification *)notification { NSValue *frameValue = notification.userInfo[UIKeyboardFrameEndUserInfoKey]; CGRect frame = [frameValue CGRectValue]; - NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; - UIViewAnimationOptions curve = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16; + // Apparently, we are in the middle of an animation block when this method is called, meaning there is no need to create one with the right duration + // and curve. Probably a bug on Apple's end, but it does work in our favor here. + self.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetMinY(frame)); - [UIView animateWithDuration:duration delay:0 options:curve animations:^{ - self.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetMinY(frame)); - } completion:nil]; + if (!self.isPresentingAlert) { + [self.alert layoutIfNeeded]; + } } @end From 1417d135bdcbff64c988e82783c84c7680ba8179 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 01:16:17 -0700 Subject: [PATCH 49/76] Convert to modern Objective-C --- SDCAlertView/Source/SDCAlertTextFieldViewController.h | 2 +- SDCAlertView/Source/SDCAlertView.h | 2 +- SDCAlertView/Source/SDCAlertView.m | 2 +- SDCAlertView/Source/SDCAlertViewContentView.h | 2 +- SDCAlertView/Source/SDCAlertViewCoordinator.m | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.h b/SDCAlertView/Source/SDCAlertTextFieldViewController.h index 324a10a3..44d8b9ef 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.h +++ b/SDCAlertView/Source/SDCAlertTextFieldViewController.h @@ -14,6 +14,6 @@ - (instancetype)initWithTextFields:(NSArray *)textFields visualStyle:(id)visualStyle; -- (CGFloat)requiredHeightForDisplayingAllTextFields; +@property (nonatomic, readonly) CGFloat requiredHeightForDisplayingAllTextFields; @end diff --git a/SDCAlertView/Source/SDCAlertView.h b/SDCAlertView/Source/SDCAlertView.h index cdb70535..777ed015 100644 --- a/SDCAlertView/Source/SDCAlertView.h +++ b/SDCAlertView/Source/SDCAlertView.h @@ -107,7 +107,7 @@ typedef NS_ENUM(NSInteger, SDCAlertViewStyle) { message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle - otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION; + otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION NS_DESIGNATED_INITIALIZER; /* * Showing and dismissing an alert works largely the same as it does with UIAlertView. Animations will not be interrupted, diff --git a/SDCAlertView/Source/SDCAlertView.m b/SDCAlertView/Source/SDCAlertView.m index 2f2e2dc6..e9433896 100644 --- a/SDCAlertView/Source/SDCAlertView.m +++ b/SDCAlertView/Source/SDCAlertView.m @@ -74,7 +74,7 @@ - (SDCAlertViewContentView *)alertContentView { #pragma mark - Initialization -- (id)init { +- (instancetype)init { return [self initWithTitle:nil message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; } diff --git a/SDCAlertView/Source/SDCAlertViewContentView.h b/SDCAlertView/Source/SDCAlertViewContentView.h index 19c3a15f..371375bf 100644 --- a/SDCAlertView/Source/SDCAlertViewContentView.h +++ b/SDCAlertView/Source/SDCAlertViewContentView.h @@ -38,7 +38,7 @@ @property (nonatomic, weak) id delegate; -- (instancetype)initWithDelegate:(id )delegate; +- (instancetype)initWithDelegate:(id )delegate NS_DESIGNATED_INITIALIZER; - (void)updateContentForStyle:(SDCAlertViewStyle)style; - (void)prepareForShowing; diff --git a/SDCAlertView/Source/SDCAlertViewCoordinator.m b/SDCAlertView/Source/SDCAlertViewCoordinator.m index 3320c5ef..c5f63a36 100644 --- a/SDCAlertView/Source/SDCAlertViewCoordinator.m +++ b/SDCAlertView/Source/SDCAlertViewCoordinator.m @@ -40,7 +40,7 @@ - (NSMutableArray *)alerts { return _alerts; } -- (id)init { +- (instancetype)init { self = [super init]; if (self) { From 7e1d0eaa4bd83da6b5bb87b69690ef54eb00176b Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 13:14:32 -0700 Subject: [PATCH 50/76] Replace hardcoded scale with constant --- SDCAlertView/Source/SDCAlertTransition.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SDCAlertView/Source/SDCAlertTransition.m b/SDCAlertView/Source/SDCAlertTransition.m index d3de8eb7..6a9364f7 100644 --- a/SDCAlertView/Source/SDCAlertTransition.m +++ b/SDCAlertView/Source/SDCAlertTransition.m @@ -12,6 +12,7 @@ static CGFloat const SDCAlertAnimationControllerSpringDamping = 45.71; static CGFloat const SDCAlertAnimationControllerSpringVelocity = 0; +static CGFloat const SDCAlertAnimationControllerInitialScale = 1.26; @implementation SDCAlertTransitioningDelegate @@ -60,7 +61,7 @@ - (void)animateTransition:(id)transitionCo animatingView.frame = [transitionContext finalFrameForViewController:animatingViewController]; if (self.isPresentation) { - animatingView.transform = CGAffineTransformMakeScale(1.26, 1.26); + animatingView.transform = CGAffineTransformMakeScale(SDCAlertAnimationControllerInitialScale, SDCAlertAnimationControllerInitialScale); animatingView.alpha = 0; [self animate:^{ From e4eac3ceeb11a84d39da0ffb29e25ad04946cdcd Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 14:07:37 -0700 Subject: [PATCH 51/76] Verify visual style with UIAlertControllerVisualStyleAlert --- SDCAlertView/SDCViewController.m | 2 +- .../Source/SDCAlertControllerDefaultVisualStyle.m | 4 ++++ SDCAlertView/Source/SDCAlertControllerView.m | 8 ++++++-- SDCAlertView/Source/SDCAlertControllerVisualStyle.h | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index 4b3f7774..ce51941a 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -32,7 +32,7 @@ - (void)presentNow { //[b addTextFieldWithConfigurationHandler:nil]; [self presentViewController:b animated:YES completion:^{ -// b.title = nil; + NSLog(@"%@", [b valueForKey:@"styleProvider"]); }]; } diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index 18ca683a..83442739 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -12,6 +12,10 @@ @implementation SDCAlertControllerDefaultVisualStyle +- (CGFloat)cornerRadius { + return 7; +} + - (CGFloat)width { return 270; } diff --git a/SDCAlertView/Source/SDCAlertControllerView.m b/SDCAlertView/Source/SDCAlertControllerView.m index 8108b8b4..71646106 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -35,8 +35,6 @@ - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedS if (self) { UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]; _visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; - _visualEffectView.layer.masksToBounds = YES; - _visualEffectView.layer.cornerRadius = 5; [_visualEffectView setTranslatesAutoresizingMaskIntoConstraints:NO]; _scrollView = [[SDCAlertScrollView alloc] initWithTitle:title message:message]; @@ -87,6 +85,12 @@ - (void)setActionLayout:(SDCAlertControllerActionLayout)actionLayout { self.collectionViewLayout.scrollDirection = direction; } +- (void)setVisualStyle:(id)visualStyle { + _visualStyle = visualStyle; + self.layer.masksToBounds = YES; + self.layer.cornerRadius = visualStyle.cornerRadius; +} + - (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController { self.scrollView.textFieldViewController = viewController; } diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index bf2083a8..0f9c1643 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -12,6 +12,8 @@ @protocol SDCAlertControllerVisualStyle +@property (nonatomic, readonly) CGFloat cornerRadius; + @property (nonatomic, readonly) CGFloat width; @property (nonatomic, readonly) CGFloat actionViewHeight; @property (nonatomic, readonly) CGFloat actionViewTopSpacingWithContentView; From 16bbf1cddeed7fb51937f9711dd29bf3dd815072 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 14:23:15 -0700 Subject: [PATCH 52/76] Add parallax effect --- SDCAlertView.xcodeproj/project.pbxproj | 6 ++++ .../SDCAlertControllerDefaultVisualStyle.m | 4 +++ SDCAlertView/Source/SDCAlertControllerView.m | 3 ++ .../Source/SDCAlertControllerVisualStyle.h | 1 + SDCAlertView/Source/SDCAlertView.m | 20 ++---------- SDCAlertView/Source/UIView+Parallax.h | 15 +++++++++ SDCAlertView/Source/UIView+Parallax.m | 31 +++++++++++++++++++ 7 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 SDCAlertView/Source/UIView+Parallax.h create mode 100644 SDCAlertView/Source/UIView+Parallax.m diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index 456c59c2..e5d279f9 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ D2AE983119DFBDF50083AB0C /* UIViewController+Current.m in Sources */ = {isa = PBXBuildFile; fileRef = D2AE983019DFBDF50083AB0C /* UIViewController+Current.m */; }; D2BD0CC418FEB2C400520E33 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC318FEB2C400520E33 /* iPad.storyboard */; }; D2BD0CC618FED65700520E33 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC518FED65700520E33 /* CHANGELOG.md */; }; + D2CABE9519E1ECFE00CA1A89 /* UIView+Parallax.m in Sources */ = {isa = PBXBuildFile; fileRef = D2CABE9419E1ECFE00CA1A89 /* UIView+Parallax.m */; }; D2D5A77019D8A64B00386078 /* SDCAlertTextFieldViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */; }; D2F8345918EF2893000BB281 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = D2F8345718EF2887000BB281 /* Podfile */; }; D2F9D2BD18400CD300F85B10 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = D2F9D2BC18400CD200F85B10 /* README.md */; }; @@ -118,6 +119,8 @@ D2AE983019DFBDF50083AB0C /* UIViewController+Current.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Current.m"; sourceTree = ""; }; D2BD0CC318FEB2C400520E33 /* iPad.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = iPad.storyboard; sourceTree = ""; }; D2BD0CC518FED65700520E33 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CHANGELOG.md; sourceTree = ""; }; + D2CABE9319E1ECFE00CA1A89 /* UIView+Parallax.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Parallax.h"; sourceTree = ""; }; + D2CABE9419E1ECFE00CA1A89 /* UIView+Parallax.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Parallax.m"; sourceTree = ""; }; D2D5A76E19D8A64B00386078 /* SDCAlertTextFieldViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertTextFieldViewController.h; sourceTree = ""; }; D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertTextFieldViewController.m; sourceTree = ""; }; D2F8345718EF2887000BB281 /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = ""; }; @@ -293,6 +296,8 @@ D2F8347218EF2C09000BB281 /* Source */ = { isa = PBXGroup; children = ( + D2CABE9319E1ECFE00CA1A89 /* UIView+Parallax.h */, + D2CABE9419E1ECFE00CA1A89 /* UIView+Parallax.m */, D26506EE19C61B7500BF34B9 /* 1.0 */, D26506EF19C61B8000BF34B9 /* 2.0 */, ); @@ -477,6 +482,7 @@ D2D5A77019D8A64B00386078 /* SDCAlertTextFieldViewController.m in Sources */, D259FC1519CEB0EB00BA6B36 /* SDCAlertTransition.m in Sources */, D2988E0319D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m in Sources */, + D2CABE9519E1ECFE00CA1A89 /* UIView+Parallax.m in Sources */, D259FC1219CEB02100BA6B36 /* SDCAlertPresentationController.m in Sources */, D25B3CDE17ECF1C5004B32A2 /* SDCAlertView.m in Sources */, D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */, diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index 83442739..eb10f902 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -16,6 +16,10 @@ - (CGFloat)cornerRadius { return 7; } +- (UIOffset)parallax { + return UIOffsetMake(15.75, 15.75); +} + - (CGFloat)width { return 270; } diff --git a/SDCAlertView/Source/SDCAlertControllerView.m b/SDCAlertView/Source/SDCAlertControllerView.m index 71646106..d2a9b315 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -16,6 +16,7 @@ #import "SDCIntrinsicallySizedView.h" #import "UIView+SDCAutoLayout.h" +#import "UIView+Parallax.h" static NSString *const SDCAlertControllerCellReuseIdentifier = @"SDCAlertControllerCellReuseIdentifier"; @@ -89,6 +90,8 @@ - (void)setVisualStyle:(id)visualStyle { _visualStyle = visualStyle; self.layer.masksToBounds = YES; self.layer.cornerRadius = visualStyle.cornerRadius; + + [self sdc_addParallax:self.visualStyle.parallax]; } - (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController { diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index 0f9c1643..ba84f5b8 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -13,6 +13,7 @@ @protocol SDCAlertControllerVisualStyle @property (nonatomic, readonly) CGFloat cornerRadius; +@property (nonatomic, readonly) UIOffset parallax; @property (nonatomic, readonly) CGFloat width; @property (nonatomic, readonly) CGFloat actionViewHeight; diff --git a/SDCAlertView/Source/SDCAlertView.m b/SDCAlertView/Source/SDCAlertView.m index e9433896..2c3cfae7 100644 --- a/SDCAlertView/Source/SDCAlertView.m +++ b/SDCAlertView/Source/SDCAlertView.m @@ -14,6 +14,7 @@ #import "SDCAlertViewContentView.h" #import "UIView+SDCAutoLayout.h" +#import "UIView+Parallax.h" CGFloat const SDCAlertViewWidth = 270; static UIEdgeInsets const SDCAlertViewPadding = {3, 0, 3, 0}; @@ -88,7 +89,7 @@ - (instancetype)initWithTitle:(NSString *)title if (self) { [self setTranslatesAutoresizingMaskIntoConstraints:NO]; - [self addParallaxEffect]; + [self sdc_addParallax:SDCAlertViewParallaxSlideMagnitude]; self.layer.masksToBounds = YES; self.layer.cornerRadius = SDCAlertViewCornerRadius; @@ -107,23 +108,6 @@ - (instancetype)initWithTitle:(NSString *)title return self; } -- (void)addParallaxEffect { - UIInterpolatingMotionEffect *horizontalParallax; - UIInterpolatingMotionEffect *verticalParallax; - - horizontalParallax = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; - horizontalParallax.minimumRelativeValue = @(-SDCAlertViewParallaxSlideMagnitude.horizontal); - horizontalParallax.maximumRelativeValue = @(SDCAlertViewParallaxSlideMagnitude.horizontal); - - verticalParallax = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; - verticalParallax.minimumRelativeValue = @(-SDCAlertViewParallaxSlideMagnitude.vertical); - verticalParallax.maximumRelativeValue = @(SDCAlertViewParallaxSlideMagnitude.vertical); - - UIMotionEffectGroup *groupMotionEffect = [[UIMotionEffectGroup alloc] init]; - groupMotionEffect.motionEffects = @[horizontalParallax, verticalParallax]; - [self addMotionEffect:groupMotionEffect]; -} - #pragma mark - Visibility - (BOOL)isVisible { diff --git a/SDCAlertView/Source/UIView+Parallax.h b/SDCAlertView/Source/UIView+Parallax.h new file mode 100644 index 00000000..71c2ce52 --- /dev/null +++ b/SDCAlertView/Source/UIView+Parallax.h @@ -0,0 +1,15 @@ +// +// UIView+Parallax.h +// SDCAlertView +// +// Created by Scott Berrevoets on 10/5/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +@interface UIView (Parallax) + +- (void)sdc_addParallax:(UIOffset)magnitude; + +@end diff --git a/SDCAlertView/Source/UIView+Parallax.m b/SDCAlertView/Source/UIView+Parallax.m new file mode 100644 index 00000000..1dd4491b --- /dev/null +++ b/SDCAlertView/Source/UIView+Parallax.m @@ -0,0 +1,31 @@ +// +// UIView+Parallax.m +// SDCAlertView +// +// Created by Scott Berrevoets on 10/5/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "UIView+Parallax.h" + +@implementation UIView (Parallax) + +- (void)sdc_addParallax:(UIOffset)magnitude { + UIInterpolatingMotionEffect *horizontalParallax; + UIInterpolatingMotionEffect *verticalParallax; + + horizontalParallax = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; + horizontalParallax.minimumRelativeValue = @(-magnitude.horizontal); + horizontalParallax.maximumRelativeValue = @(magnitude.horizontal); + + verticalParallax = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; + verticalParallax.minimumRelativeValue = @(-magnitude.vertical); + verticalParallax.maximumRelativeValue = @(magnitude.vertical); + + UIMotionEffectGroup *groupMotionEffect = [[UIMotionEffectGroup alloc] init]; + groupMotionEffect.motionEffects = @[horizontalParallax, verticalParallax]; + + [self addMotionEffect:groupMotionEffect]; +} + +@end From c4eccf726b218bf4d9e29d1cf1ca023d0edf795c Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 14:24:33 -0700 Subject: [PATCH 53/76] Add SDC prefix to avoid potential naming collision --- SDCAlertView/Source/SDCAlertController.m | 2 +- SDCAlertView/Source/UIViewController+Current.h | 2 +- SDCAlertView/Source/UIViewController+Current.m | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index d09b1d36..93e5aa6a 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -241,7 +241,7 @@ - (void)present { } - (void)presentWithCompletion:(void(^)(void))completion { - UIViewController *currentViewController = [UIViewController currentViewController]; + UIViewController *currentViewController = [UIViewController sdc_currentViewController]; [self presentFromViewController:currentViewController completionHandler:completion]; } diff --git a/SDCAlertView/Source/UIViewController+Current.h b/SDCAlertView/Source/UIViewController+Current.h index f8214832..e629ebdf 100644 --- a/SDCAlertView/Source/UIViewController+Current.h +++ b/SDCAlertView/Source/UIViewController+Current.h @@ -10,6 +10,6 @@ @interface UIViewController (Current) -+ (UIViewController *)currentViewController; ++ (UIViewController *)sdc_currentViewController; @end diff --git a/SDCAlertView/Source/UIViewController+Current.m b/SDCAlertView/Source/UIViewController+Current.m index 0b352c4a..200ffd0d 100644 --- a/SDCAlertView/Source/UIViewController+Current.m +++ b/SDCAlertView/Source/UIViewController+Current.m @@ -10,19 +10,19 @@ @implementation UIViewController (Current) -+ (UIViewController *)currentViewController { ++ (UIViewController *)sdc_currentViewController { UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController]; - return [self topViewControllerForViewController:rootViewController]; + return [self sdc_topViewControllerForViewController:rootViewController]; } -+ (UIViewController *)topViewControllerForViewController:(UIViewController *)rootViewController { ++ (UIViewController *)sdc_topViewControllerForViewController:(UIViewController *)rootViewController { if ([rootViewController isKindOfClass:[UINavigationController class]]) { UINavigationController *navigationController = (UINavigationController *)rootViewController; - return [self topViewControllerForViewController:navigationController.visibleViewController]; + return [self sdc_topViewControllerForViewController:navigationController.visibleViewController]; } if (rootViewController.presentedViewController) { - return [self topViewControllerForViewController:rootViewController.presentedViewController]; + return [self sdc_topViewControllerForViewController:rootViewController.presentedViewController]; } return rootViewController; From 05ace05f0bc6ceba126f52f3870b637d6748fecb Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 14:34:14 -0700 Subject: [PATCH 54/76] Make transform animation equal to UIAlertController --- SDCAlertView/SDCViewController.m | 2 +- SDCAlertView/Source/SDCAlertTransition.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index ce51941a..ff7d4f18 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -50,7 +50,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [ac presentWithCompletion:nil]; // [self presentNow]; - + } else if (indexPath.section == 1) { if (indexPath.row == 0) { SDCAlertView *a = [[SDCAlertView alloc] initWithTitle:@"Title" diff --git a/SDCAlertView/Source/SDCAlertTransition.m b/SDCAlertView/Source/SDCAlertTransition.m index 6a9364f7..fda2a7f7 100644 --- a/SDCAlertView/Source/SDCAlertTransition.m +++ b/SDCAlertView/Source/SDCAlertTransition.m @@ -12,7 +12,7 @@ static CGFloat const SDCAlertAnimationControllerSpringDamping = 45.71; static CGFloat const SDCAlertAnimationControllerSpringVelocity = 0; -static CGFloat const SDCAlertAnimationControllerInitialScale = 1.26; +static CGFloat const SDCAlertAnimationControllerInitialScale = 1.2; @implementation SDCAlertTransitioningDelegate From d209e37b064caa1cd3276ec2645b661f5401221a Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 15:12:14 -0700 Subject: [PATCH 55/76] Enforce SDCAlertAction enabled state in UI --- SDCAlertView/SDCViewController.m | 6 ++++- .../Source/SDCAlertCollectionViewCell.h | 1 + .../Source/SDCAlertCollectionViewCell.m | 15 +++++++++-- SDCAlertView/Source/SDCAlertController.m | 2 +- SDCAlertView/Source/SDCAlertControllerView.h | 2 +- SDCAlertView/Source/SDCAlertControllerView.m | 27 +++++++++++++++++-- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index ff7d4f18..b5eb1b45 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -48,7 +48,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath textField.delegate = self; }]; - [ac presentWithCompletion:nil]; + [ac presentWithCompletion:^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [ac.actions.firstObject setEnabled:NO]; + }); + }]; // [self presentNow]; } else if (indexPath.section == 1) { diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.h b/SDCAlertView/Source/SDCAlertCollectionViewCell.h index b7b8378a..61c91616 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.h +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.h @@ -18,6 +18,7 @@ @interface SDCAlertCollectionViewCell : UICollectionViewCell @property (nonatomic, strong) UIGestureRecognizer *gestureRecognizer; +@property (nonatomic, getter=isEnabled) BOOL enabled; - (void)updateWithAction:(SDCAlertAction *)action visualStyle:(id)visualStyle; diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 74d24c00..9bde347b 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -15,7 +15,6 @@ @interface SDCAlertCollectionViewCell () @property (nonatomic, strong) UILabel *textLabel; -@property (nonatomic, getter=isEnabled) BOOL enabled; @property (nonatomic, strong) UIView *highlightedBackgroundView; @end @@ -36,9 +35,18 @@ - (void)setGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { [self removeGestureRecognizer:_gestureRecognizer]; _gestureRecognizer = gestureRecognizer; + gestureRecognizer.enabled = self.isEnabled; [self addGestureRecognizer:gestureRecognizer]; } +- (void)setEnabled:(BOOL)enabled { + _enabled = enabled; + + self.highlightedBackgroundView.hidden = YES; // Still hide when enabling + self.textLabel.enabled = enabled; + self.gestureRecognizer.enabled = enabled; +} + - (void)updateWithAction:(SDCAlertAction *)action visualStyle:(id)visualStyle { if (action.attributedTitle) { self.textLabel.attributedText = action.attributedTitle; @@ -68,7 +76,10 @@ - (void)layoutSubviews { - (void)setHighlighted:(BOOL)highlighted { [super setHighlighted:highlighted]; - self.highlightedBackgroundView.hidden = !highlighted; + + if (self.isEnabled) { + self.highlightedBackgroundView.hidden = !highlighted; + } } @end diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 93e5aa6a..c0169186 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -150,7 +150,7 @@ - (void)viewDidLoad { [self.view addSubview:self.alert]; [self.alert sdc_centerInSuperview]; - [self.alert createViewHierarchy]; + [self.alert prepareForDisplay]; } - (void)viewDidLayoutSubviews { diff --git a/SDCAlertView/Source/SDCAlertControllerView.h b/SDCAlertView/Source/SDCAlertControllerView.h index 05821560..6a4c1e1f 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.h +++ b/SDCAlertView/Source/SDCAlertControllerView.h @@ -37,5 +37,5 @@ - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedString *)message; - (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController; -- (void)createViewHierarchy; +- (void)prepareForDisplay; @end diff --git a/SDCAlertView/Source/SDCAlertControllerView.m b/SDCAlertView/Source/SDCAlertControllerView.m index d2a9b315..e31ff471 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -91,7 +91,7 @@ - (void)setVisualStyle:(id)visualStyle { self.layer.masksToBounds = YES; self.layer.cornerRadius = visualStyle.cornerRadius; - [self sdc_addParallax:self.visualStyle.parallax]; + [self sdc_addParallax:visualStyle.parallax]; } - (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController { @@ -131,7 +131,8 @@ - (CGFloat)collectionViewHeight { } } -- (void)createViewHierarchy { +- (void)prepareForDisplay { + [self observeActions]; [self applyCurrentStyleToAlertElements]; [self.visualEffectView sdc_pinWidth:self.visualStyle.width]; @@ -162,6 +163,28 @@ - (void)createViewHierarchy { [self.visualEffectView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; } +- (void)observeActions { + [self.actions enumerateObjectsUsingBlock:^(SDCAlertAction *action, NSUInteger idx, BOOL *stop) { + [action addObserver:self forKeyPath:@"enabled" options:0 context:NULL]; + }]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + if ([object isKindOfClass:[SDCAlertAction class]]) { + SDCAlertAction *action = object; + NSIndexPath *indexPath = [NSIndexPath indexPathForItem:[self.actions indexOfObject:action] inSection:0]; + + SDCAlertCollectionViewCell *cell = (SDCAlertCollectionViewCell *)[self.actionsCollectionView cellForItemAtIndexPath:indexPath]; + cell.enabled = action.isEnabled; + } +} + +- (void)dealloc { + [self.actions enumerateObjectsUsingBlock:^(SDCAlertAction *action, NSUInteger idx, BOOL *stop) { + [action removeObserver:self forKeyPath:@"enabled"]; + }]; +} + - (void)layoutSubviews { [super layoutSubviews]; self.maximumHeightConstraint.constant = [self maximumHeightForScrollView]; From f2fda941a7980ff9f324867609e23e11594a7107 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 15:20:01 -0700 Subject: [PATCH 56/76] Remove duplicate padding --- SDCAlertView/SDCViewController.m | 2 +- .../Source/SDCAlertControllerDefaultVisualStyle.m | 8 -------- SDCAlertView/Source/SDCAlertControllerView.m | 12 ++---------- SDCAlertView/Source/SDCAlertControllerVisualStyle.h | 2 -- 4 files changed, 3 insertions(+), 21 deletions(-) diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index b5eb1b45..bd5f7267 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -32,7 +32,7 @@ - (void)presentNow { //[b addTextFieldWithConfigurationHandler:nil]; [self presentViewController:b animated:YES completion:^{ - NSLog(@"%@", [b valueForKey:@"styleProvider"]); + //NSLog(@"%@", [b valueForKey:@"styleProvider"]); }]; } diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index eb10f902..24fc5232 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -32,14 +32,6 @@ - (CGFloat)minimumActionViewWidth { return 90; // Fits exactly three actions without scrolling } -- (CGFloat)actionViewTopSpacingWithContentView { - return 0; -} - -- (CGFloat)actionViewTopSpacingWithoutContentView { - return 20; -} - - (UIEdgeInsets)margins { return UIEdgeInsetsMake(3, 0, 3, 0); } diff --git a/SDCAlertView/Source/SDCAlertControllerView.m b/SDCAlertView/Source/SDCAlertControllerView.m index e31ff471..f3cb4f00 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -99,7 +99,7 @@ - (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewContr } - (CGFloat)maximumHeightForScrollView { - CGFloat maximumHeight = CGRectGetHeight(self.superview.bounds) - self.visualStyle.margins.top - self.visualStyle.margins.bottom - [self actionViewTopSpacing]; + CGFloat maximumHeight = CGRectGetHeight(self.superview.bounds) - self.visualStyle.margins.top - self.visualStyle.margins.bottom; if (self.actions.count > 0) { if (self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) { @@ -112,14 +112,6 @@ - (CGFloat)maximumHeightForScrollView { return maximumHeight; } -- (CGFloat)actionViewTopSpacing { - if (self.contentView.subviews.count > 0) { - return self.visualStyle.actionViewTopSpacingWithContentView; - } else { - return self.visualStyle.actionViewTopSpacingWithoutContentView; - } -} - - (CGFloat)collectionViewHeight { CGFloat horizontalLayoutHeight = self.visualStyle.actionViewHeight; CGFloat verticalLayoutHeight = self.visualStyle.actionViewHeight * [self.actionsCollectionView numberOfItemsInSection:0]; @@ -155,7 +147,7 @@ - (void)prepareForDisplay { } [self.visualEffectView.contentView addSubview:self.actionsCollectionView]; - [self.actionsCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:aligningView inset:[self actionViewTopSpacing]]; + [self.actionsCollectionView sdc_alignEdge:UIRectEdgeTop withEdge:UIRectEdgeBottom ofView:aligningView]; [self.actionsCollectionView sdc_alignEdgesWithSuperview:UIRectEdgeLeft|UIRectEdgeBottom|UIRectEdgeRight]; [self.actionsCollectionView sdc_pinHeight:[self collectionViewHeight]]; diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index ba84f5b8..169c875c 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -17,8 +17,6 @@ @property (nonatomic, readonly) CGFloat width; @property (nonatomic, readonly) CGFloat actionViewHeight; -@property (nonatomic, readonly) CGFloat actionViewTopSpacingWithContentView; -@property (nonatomic, readonly) CGFloat actionViewTopSpacingWithoutContentView; @property (nonatomic, readonly) CGFloat minimumActionViewWidth; // For forced horizontal layout and 3+ buttons @property (nonatomic, readonly) UIEdgeInsets margins; From b31baec367ff32a7476eb7c687d7db6f4ff780a8 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Sun, 5 Oct 2014 15:42:07 -0700 Subject: [PATCH 57/76] Rename classes from SDCAlert to SDCAlertController --- SDCAlertView.xcodeproj/project.pbxproj | 36 +++++++++---------- SDCAlertView/SDCViewController.m | 2 +- SDCAlertView/Source/SDCAlertController.m | 8 ++--- ...lView.h => SDCAlertControllerScrollView.h} | 8 ++--- ...lView.m => SDCAlertControllerScrollView.m} | 12 +++---- ...CAlertControllerTextFieldViewController.h} | 4 +-- ...CAlertControllerTextFieldViewController.m} | 8 ++--- ...ition.h => SDCAlertControllerTransition.h} | 4 +-- ...ition.m => SDCAlertControllerTransition.m} | 6 ++-- SDCAlertView/Source/SDCAlertControllerView.h | 4 +-- SDCAlertView/Source/SDCAlertControllerView.m | 8 ++--- 11 files changed, 50 insertions(+), 50 deletions(-) rename SDCAlertView/Source/{SDCAlertScrollView.h => SDCAlertControllerScrollView.h} (67%) rename SDCAlertView/Source/{SDCAlertScrollView.m => SDCAlertControllerScrollView.m} (92%) rename SDCAlertView/Source/{SDCAlertTextFieldViewController.h => SDCAlertControllerTextFieldViewController.h} (76%) rename SDCAlertView/Source/{SDCAlertTextFieldViewController.m => SDCAlertControllerTextFieldViewController.m} (91%) rename SDCAlertView/Source/{SDCAlertTransition.h => SDCAlertControllerTransition.h} (70%) rename SDCAlertView/Source/{SDCAlertTransition.m => SDCAlertControllerTransition.m} (96%) diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index e5d279f9..ba76d83d 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ /* Begin PBXBuildFile section */ 4B64D41583994B9C9C59A4E3 /* libPods-SDCAlertViewTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CB28936541154BCF9C9B2F0C /* libPods-SDCAlertViewTests.a */; }; D259FC1219CEB02100BA6B36 /* SDCAlertPresentationController.m in Sources */ = {isa = PBXBuildFile; fileRef = D259FC1119CEB02100BA6B36 /* SDCAlertPresentationController.m */; }; - D259FC1519CEB0EB00BA6B36 /* SDCAlertTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = D259FC1419CEB0EB00BA6B36 /* SDCAlertTransition.m */; }; + D259FC1519CEB0EB00BA6B36 /* SDCAlertControllerTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = D259FC1419CEB0EB00BA6B36 /* SDCAlertControllerTransition.m */; }; D25B3CA817ECE7A6004B32A2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D25B3CA717ECE7A6004B32A2 /* Foundation.framework */; }; D25B3CAA17ECE7A6004B32A2 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D25B3CA917ECE7A6004B32A2 /* CoreGraphics.framework */; }; D25B3CAC17ECE7A6004B32A2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D25B3CAB17ECE7A6004B32A2 /* UIKit.framework */; }; @@ -30,7 +30,7 @@ D26506F219C67FC300BF34B9 /* SDCAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F119C67FC300BF34B9 /* SDCAlertController.m */; }; D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */ = {isa = PBXBuildFile; fileRef = D26506F319C6812600BF34B9 /* SDCAlertAction.m */; }; D2666A4019CFDE2800167157 /* SDCAlertControllerView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A3F19CFDE2800167157 /* SDCAlertControllerView.m */; }; - D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */; }; + D2666A4319CFDF6700167157 /* SDCAlertControllerScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4219CFDF6700167157 /* SDCAlertControllerScrollView.m */; }; D2666A4619CFE0F900167157 /* SDCAlertLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4519CFE0F900167157 /* SDCAlertLabel.m */; }; D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */ = {isa = PBXBuildFile; fileRef = D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */; }; D2988E0319D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = D2988E0219D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m */; }; @@ -42,7 +42,7 @@ D2BD0CC418FEB2C400520E33 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC318FEB2C400520E33 /* iPad.storyboard */; }; D2BD0CC618FED65700520E33 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC518FED65700520E33 /* CHANGELOG.md */; }; D2CABE9519E1ECFE00CA1A89 /* UIView+Parallax.m in Sources */ = {isa = PBXBuildFile; fileRef = D2CABE9419E1ECFE00CA1A89 /* UIView+Parallax.m */; }; - D2D5A77019D8A64B00386078 /* SDCAlertTextFieldViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */; }; + D2D5A77019D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2D5A76F19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m */; }; D2F8345918EF2893000BB281 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = D2F8345718EF2887000BB281 /* Podfile */; }; D2F9D2BD18400CD300F85B10 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = D2F9D2BC18400CD200F85B10 /* README.md */; }; D2F9D2BF18400DAF00F85B10 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = D2F9D2BE18400DAF00F85B10 /* LICENSE */; }; @@ -65,8 +65,8 @@ CB28936541154BCF9C9B2F0C /* libPods-SDCAlertViewTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-SDCAlertViewTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; D259FC1019CEB02100BA6B36 /* SDCAlertPresentationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertPresentationController.h; sourceTree = ""; }; D259FC1119CEB02100BA6B36 /* SDCAlertPresentationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertPresentationController.m; sourceTree = ""; }; - D259FC1319CEB0EB00BA6B36 /* SDCAlertTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertTransition.h; sourceTree = ""; }; - D259FC1419CEB0EB00BA6B36 /* SDCAlertTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertTransition.m; sourceTree = ""; }; + D259FC1319CEB0EB00BA6B36 /* SDCAlertControllerTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerTransition.h; sourceTree = ""; }; + D259FC1419CEB0EB00BA6B36 /* SDCAlertControllerTransition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerTransition.m; sourceTree = ""; }; D25B3CA417ECE7A6004B32A2 /* SDCAlertView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SDCAlertView.app; sourceTree = BUILT_PRODUCTS_DIR; }; D25B3CA717ECE7A6004B32A2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; D25B3CA917ECE7A6004B32A2 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -98,8 +98,8 @@ D26506F319C6812600BF34B9 /* SDCAlertAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertAction.m; sourceTree = ""; }; D2666A3E19CFDE2800167157 /* SDCAlertControllerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerView.h; sourceTree = ""; }; D2666A3F19CFDE2800167157 /* SDCAlertControllerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerView.m; sourceTree = ""; }; - D2666A4119CFDF6700167157 /* SDCAlertScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertScrollView.h; sourceTree = ""; }; - D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertScrollView.m; sourceTree = ""; }; + D2666A4119CFDF6700167157 /* SDCAlertControllerScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerScrollView.h; sourceTree = ""; }; + D2666A4219CFDF6700167157 /* SDCAlertControllerScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerScrollView.m; sourceTree = ""; }; D2666A4419CFE0F900167157 /* SDCAlertLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertLabel.h; sourceTree = ""; }; D2666A4519CFE0F900167157 /* SDCAlertLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertLabel.m; sourceTree = ""; }; D268093118F845420001B7E9 /* SDCAlertViewTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCAlertViewTransitioning.h; sourceTree = ""; }; @@ -121,8 +121,8 @@ D2BD0CC518FED65700520E33 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CHANGELOG.md; sourceTree = ""; }; D2CABE9319E1ECFE00CA1A89 /* UIView+Parallax.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Parallax.h"; sourceTree = ""; }; D2CABE9419E1ECFE00CA1A89 /* UIView+Parallax.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Parallax.m"; sourceTree = ""; }; - D2D5A76E19D8A64B00386078 /* SDCAlertTextFieldViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertTextFieldViewController.h; sourceTree = ""; }; - D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertTextFieldViewController.m; sourceTree = ""; }; + D2D5A76E19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerTextFieldViewController.h; sourceTree = ""; }; + D2D5A76F19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerTextFieldViewController.m; sourceTree = ""; }; D2F8345718EF2887000BB281 /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = ""; }; D2F9D2BC18400CD200F85B10 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = ""; }; D2F9D2BE18400DAF00F85B10 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; @@ -265,8 +265,8 @@ children = ( D2AE982F19DFBDF50083AB0C /* UIViewController+Current.h */, D2AE983019DFBDF50083AB0C /* UIViewController+Current.m */, - D2D5A76E19D8A64B00386078 /* SDCAlertTextFieldViewController.h */, - D2D5A76F19D8A64B00386078 /* SDCAlertTextFieldViewController.m */, + D2D5A76E19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.h */, + D2D5A76F19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m */, D2A6F1C319D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.h */, D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */, D2988E0519D7960900140116 /* SDCAlertControllerVisualStyle.h */, @@ -276,14 +276,14 @@ D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */, D2A6A0D919D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.h */, D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */, - D2666A4119CFDF6700167157 /* SDCAlertScrollView.h */, - D2666A4219CFDF6700167157 /* SDCAlertScrollView.m */, + D2666A4119CFDF6700167157 /* SDCAlertControllerScrollView.h */, + D2666A4219CFDF6700167157 /* SDCAlertControllerScrollView.m */, D2666A4419CFE0F900167157 /* SDCAlertLabel.h */, D2666A4519CFE0F900167157 /* SDCAlertLabel.m */, D259FC1019CEB02100BA6B36 /* SDCAlertPresentationController.h */, D259FC1119CEB02100BA6B36 /* SDCAlertPresentationController.m */, - D259FC1319CEB0EB00BA6B36 /* SDCAlertTransition.h */, - D259FC1419CEB0EB00BA6B36 /* SDCAlertTransition.m */, + D259FC1319CEB0EB00BA6B36 /* SDCAlertControllerTransition.h */, + D259FC1419CEB0EB00BA6B36 /* SDCAlertControllerTransition.m */, D26506F019C67FC300BF34B9 /* SDCAlertController.h */, D26506F119C67FC300BF34B9 /* SDCAlertController.m */, D2988E0119D794C100140116 /* SDCAlertControllerDefaultVisualStyle.h */, @@ -479,13 +479,13 @@ D2A6F1C519D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m in Sources */, D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */, D25B3CB417ECE7A6004B32A2 /* main.m in Sources */, - D2D5A77019D8A64B00386078 /* SDCAlertTextFieldViewController.m in Sources */, - D259FC1519CEB0EB00BA6B36 /* SDCAlertTransition.m in Sources */, + D2D5A77019D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m in Sources */, + D259FC1519CEB0EB00BA6B36 /* SDCAlertControllerTransition.m in Sources */, D2988E0319D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m in Sources */, D2CABE9519E1ECFE00CA1A89 /* UIView+Parallax.m in Sources */, D259FC1219CEB02100BA6B36 /* SDCAlertPresentationController.m in Sources */, D25B3CDE17ECF1C5004B32A2 /* SDCAlertView.m in Sources */, - D2666A4319CFDF6700167157 /* SDCAlertScrollView.m in Sources */, + D2666A4319CFDF6700167157 /* SDCAlertControllerScrollView.m in Sources */, D2A6A0DB19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m in Sources */, D2666A4019CFDE2800167157 /* SDCAlertControllerView.m in Sources */, D26506F419C6812600BF34B9 /* SDCAlertAction.m in Sources */, diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index bd5f7267..db6a4950 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -14,7 +14,7 @@ #import "UIView+SDCAutoLayout.h" #import "SDCAlertController.h" -#import "SDCAlertTransition.h" +#import "SDCAlertControllerTransition.h" @interface SDCViewController () @end diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index c0169186..e5894e6e 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -8,8 +8,8 @@ #import "SDCAlertController.h" -#import "SDCAlertTextFieldViewController.h" -#import "SDCAlertTransition.h" +#import "SDCAlertControllerTextFieldViewController.h" +#import "SDCAlertControllerTransition.h" #import "SDCAlertControllerView.h" #import "SDCAlertControllerDefaultVisualStyle.h" #import "SDCIntrinsicallySizedView.h" @@ -58,7 +58,7 @@ - (instancetype)initWithStyle:(SDCAlertControllerStyle)style { _actionLayout = SDCAlertControllerActionLayoutAutomatic; self.modalPresentationStyle = UIModalPresentationCustom; - self.transitioningDelegate = [[SDCAlertTransitioningDelegate alloc] init]; + self.transitioningDelegate = [[SDCAlertControllerTransitioningDelegate alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardUpdate:) name:UIKeyboardWillChangeFrameNotification object:nil]; } @@ -122,7 +122,7 @@ - (void)createAlert { - (void)showTextFieldsInAlertView:(SDCAlertControllerView *)alertView { if (self.textFields.count > 0) { - SDCAlertTextFieldViewController *textFieldViewController = [[SDCAlertTextFieldViewController alloc] initWithTextFields:self.textFields + SDCAlertControllerTextFieldViewController *textFieldViewController = [[SDCAlertControllerTextFieldViewController alloc] initWithTextFields:self.textFields visualStyle:self.visualStyle]; [self addChildViewController:textFieldViewController]; [alertView showTextFieldViewController:textFieldViewController]; diff --git a/SDCAlertView/Source/SDCAlertScrollView.h b/SDCAlertView/Source/SDCAlertControllerScrollView.h similarity index 67% rename from SDCAlertView/Source/SDCAlertScrollView.h rename to SDCAlertView/Source/SDCAlertControllerScrollView.h index afdd16a2..173a401e 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.h +++ b/SDCAlertView/Source/SDCAlertControllerScrollView.h @@ -1,5 +1,5 @@ // -// SDCAlertScrollView.h +// SDCAlertControllerScrollView.h // SDCAlertView // // Created by Scott Berrevoets on 9/21/14. @@ -10,14 +10,14 @@ #import "SDCAlertControllerVisualStyle.h" -@class SDCAlertTextFieldViewController; +@class SDCAlertControllerTextFieldViewController; -@interface SDCAlertScrollView : UIScrollView +@interface SDCAlertControllerScrollView : UIScrollView @property (nonatomic, strong) NSAttributedString *title; @property (nonatomic, strong) NSAttributedString *message; -@property (nonatomic, strong) SDCAlertTextFieldViewController *textFieldViewController; +@property (nonatomic, strong) SDCAlertControllerTextFieldViewController *textFieldViewController; @property (nonatomic, strong) id visualStyle; - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedString *)message; diff --git a/SDCAlertView/Source/SDCAlertScrollView.m b/SDCAlertView/Source/SDCAlertControllerScrollView.m similarity index 92% rename from SDCAlertView/Source/SDCAlertScrollView.m rename to SDCAlertView/Source/SDCAlertControllerScrollView.m index 0a87b357..f1445da2 100644 --- a/SDCAlertView/Source/SDCAlertScrollView.m +++ b/SDCAlertView/Source/SDCAlertControllerScrollView.m @@ -1,24 +1,24 @@ // -// SDCAlertScrollView.m +// SDCAlertControllerScrollView.m // SDCAlertView // // Created by Scott Berrevoets on 9/21/14. // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import "SDCAlertScrollView.h" +#import "SDCAlertControllerScrollView.h" -#import "SDCAlertTextFieldViewController.h" +#import "SDCAlertControllerTextFieldViewController.h" #import "SDCAlertLabel.h" #import "UIView+SDCAutoLayout.h" -@interface SDCAlertScrollView () +@interface SDCAlertControllerScrollView () @property (nonatomic, strong) SDCAlertLabel *titleLabel; @property (nonatomic, strong) SDCAlertLabel *messageLabel; @end -@implementation SDCAlertScrollView +@implementation SDCAlertControllerScrollView - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedString *)message { self = [self init]; @@ -63,7 +63,7 @@ - (void)setVisualStyle:(id)visualStyle { [self setNeedsLayout]; } -- (void)setTextFieldViewController:(SDCAlertTextFieldViewController *)textFieldViewController { +- (void)setTextFieldViewController:(SDCAlertControllerTextFieldViewController *)textFieldViewController { _textFieldViewController = textFieldViewController; [textFieldViewController.view setTranslatesAutoresizingMaskIntoConstraints:NO]; diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.h b/SDCAlertView/Source/SDCAlertControllerTextFieldViewController.h similarity index 76% rename from SDCAlertView/Source/SDCAlertTextFieldViewController.h rename to SDCAlertView/Source/SDCAlertControllerTextFieldViewController.h index 44d8b9ef..2db4d3b0 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.h +++ b/SDCAlertView/Source/SDCAlertControllerTextFieldViewController.h @@ -1,5 +1,5 @@ // -// SDCAlertTextFieldViewController.h +// SDCAlertControllerTextFieldViewController.h // SDCAlertView // // Created by Scott Berrevoets on 9/28/14. @@ -10,7 +10,7 @@ @protocol SDCAlertControllerVisualStyle; -@interface SDCAlertTextFieldViewController : UITableViewController +@interface SDCAlertControllerTextFieldViewController : UITableViewController - (instancetype)initWithTextFields:(NSArray *)textFields visualStyle:(id)visualStyle; diff --git a/SDCAlertView/Source/SDCAlertTextFieldViewController.m b/SDCAlertView/Source/SDCAlertControllerTextFieldViewController.m similarity index 91% rename from SDCAlertView/Source/SDCAlertTextFieldViewController.m rename to SDCAlertView/Source/SDCAlertControllerTextFieldViewController.m index 426abfa8..6a4a54de 100644 --- a/SDCAlertView/Source/SDCAlertTextFieldViewController.m +++ b/SDCAlertView/Source/SDCAlertControllerTextFieldViewController.m @@ -1,24 +1,24 @@ // -// SDCAlertTextFieldViewController.m +// SDCAlertControllerTextFieldViewController.m // SDCAlertView // // Created by Scott Berrevoets on 9/28/14. // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import "SDCAlertTextFieldViewController.h" +#import "SDCAlertControllerTextFieldViewController.h" #import "SDCAlertControllerVisualStyle.h" #import "SDCAlertTextFieldTableViewCell.h" static NSString *const SDCAlertTextFieldCellIdentifier = @"SDCAlertTextFieldCellIdentifier"; -@interface SDCAlertTextFieldViewController () +@interface SDCAlertControllerTextFieldViewController () @property (nonatomic, strong) NSArray *textFields; @property (nonatomic, strong) id visualStyle; @end -@implementation SDCAlertTextFieldViewController +@implementation SDCAlertControllerTextFieldViewController - (instancetype)initWithTextFields:(NSArray *)textFields visualStyle:(id)visualStyle { self = [self init]; diff --git a/SDCAlertView/Source/SDCAlertTransition.h b/SDCAlertView/Source/SDCAlertControllerTransition.h similarity index 70% rename from SDCAlertView/Source/SDCAlertTransition.h rename to SDCAlertView/Source/SDCAlertControllerTransition.h index e1c28041..add8ff3c 100644 --- a/SDCAlertView/Source/SDCAlertTransition.h +++ b/SDCAlertView/Source/SDCAlertControllerTransition.h @@ -1,5 +1,5 @@ // -// SDCAlertTransition.h +// SDCAlertControllerTransition.h // SDCAlertView // // Created by Scott Berrevoets on 9/21/14. @@ -12,6 +12,6 @@ @property (nonatomic, getter=isPresentation) BOOL presentation; @end -@interface SDCAlertTransitioningDelegate : NSObject +@interface SDCAlertControllerTransitioningDelegate : NSObject @end diff --git a/SDCAlertView/Source/SDCAlertTransition.m b/SDCAlertView/Source/SDCAlertControllerTransition.m similarity index 96% rename from SDCAlertView/Source/SDCAlertTransition.m rename to SDCAlertView/Source/SDCAlertControllerTransition.m index fda2a7f7..95318d46 100644 --- a/SDCAlertView/Source/SDCAlertTransition.m +++ b/SDCAlertView/Source/SDCAlertControllerTransition.m @@ -1,12 +1,12 @@ // -// SDCAlertTransition.m +// SDCAlertControllerTransition.m // SDCAlertView // // Created by Scott Berrevoets on 9/21/14. // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import "SDCAlertTransition.h" +#import "SDCAlertControllerTransition.h" #import "SDCAlertPresentationController.h" @@ -14,7 +14,7 @@ static CGFloat const SDCAlertAnimationControllerSpringVelocity = 0; static CGFloat const SDCAlertAnimationControllerInitialScale = 1.2; -@implementation SDCAlertTransitioningDelegate +@implementation SDCAlertControllerTransitioningDelegate - (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting diff --git a/SDCAlertView/Source/SDCAlertControllerView.h b/SDCAlertView/Source/SDCAlertControllerView.h index 6a4c1e1f..d4a4fc22 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.h +++ b/SDCAlertView/Source/SDCAlertControllerView.h @@ -12,7 +12,7 @@ @class SDCAlertControllerView; @class SDCAlertAction; -@class SDCAlertTextFieldViewController; +@class SDCAlertControllerTextFieldViewController; @protocol SDCAlertControllerViewDelegate - (void)alertControllerView:(SDCAlertControllerView *)sender didPerformAction:(SDCAlertAction *)action; @@ -36,6 +36,6 @@ - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedString *)message; -- (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController; +- (void)showTextFieldViewController:(SDCAlertControllerTextFieldViewController *)viewController; - (void)prepareForDisplay; @end diff --git a/SDCAlertView/Source/SDCAlertControllerView.m b/SDCAlertView/Source/SDCAlertControllerView.m index f3cb4f00..c06d2f75 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -10,7 +10,7 @@ #import "SDCAlertController.h" #import "SDCAlertViewBackgroundView.h" -#import "SDCAlertScrollView.h" +#import "SDCAlertControllerScrollView.h" #import "SDCAlertControllerCollectionViewFlowLayout.h" #import "SDCAlertCollectionViewCell.h" #import "SDCIntrinsicallySizedView.h" @@ -22,7 +22,7 @@ @interface SDCAlertControllerView () @property (nonatomic, strong) UIVisualEffectView *visualEffectView; -@property (nonatomic, strong) SDCAlertScrollView *scrollView; +@property (nonatomic, strong) SDCAlertControllerScrollView *scrollView; @property (nonatomic, strong) UICollectionView *actionsCollectionView; @property (nonatomic, strong) SDCAlertControllerCollectionViewFlowLayout *collectionViewLayout; @property (nonatomic, strong) NSLayoutConstraint *maximumHeightConstraint; @@ -38,7 +38,7 @@ - (instancetype)initWithTitle:(NSAttributedString *)title message:(NSAttributedS _visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; [_visualEffectView setTranslatesAutoresizingMaskIntoConstraints:NO]; - _scrollView = [[SDCAlertScrollView alloc] initWithTitle:title message:message]; + _scrollView = [[SDCAlertControllerScrollView alloc] initWithTitle:title message:message]; _collectionViewLayout = [[SDCAlertControllerCollectionViewFlowLayout alloc] init]; [_collectionViewLayout registerClass:[SDCAlertControllerSeparatorView class] forDecorationViewOfKind:SDCAlertControllerDecorationKindHorizontalSeparator]; @@ -94,7 +94,7 @@ - (void)setVisualStyle:(id)visualStyle { [self sdc_addParallax:visualStyle.parallax]; } -- (void)showTextFieldViewController:(SDCAlertTextFieldViewController *)viewController { +- (void)showTextFieldViewController:(SDCAlertControllerTextFieldViewController *)viewController { self.scrollView.textFieldViewController = viewController; } From 9d5942331f552b92509d8bae0df4ccb1da4eebcb Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 6 Oct 2014 00:33:05 -0700 Subject: [PATCH 58/76] Make 2.0 backwards compatible with 1.0 --- SDCAlertView.xcodeproj/project.pbxproj | 4 +- SDCAlertView/SDCViewController.m | 8 ++-- SDCAlertView/Source/SDCAlertController.h | 19 +++++--- SDCAlertView/Source/SDCAlertController.m | 56 +++++++++++----------- SDCAlertView/Source/SDCAlertView.h | 8 ++++ SDCAlertView/Source/SDCAlertView.m | 60 ++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 40 deletions(-) diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index ba76d83d..0263dae9 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -252,8 +252,6 @@ D263F10F1829D1860001E4E0 /* SDCAlertViewController.m */, D263F1141829D31E0001E4E0 /* SDCAlertViewContentView.h */, D263F1151829D31E0001E4E0 /* SDCAlertViewContentView.m */, - D294876A18D631B700E3D967 /* SDCIntrinsicallySizedView.h */, - D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */, D263F1111829D2BD0001E4E0 /* SDCAlertViewBackgroundView.h */, D263F1121829D2BD0001E4E0 /* SDCAlertViewBackgroundView.m */, ); @@ -298,6 +296,8 @@ children = ( D2CABE9319E1ECFE00CA1A89 /* UIView+Parallax.h */, D2CABE9419E1ECFE00CA1A89 /* UIView+Parallax.m */, + D294876A18D631B700E3D967 /* SDCIntrinsicallySizedView.h */, + D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */, D26506EE19C61B7500BF34B9 /* 1.0 */, D26506EF19C61B8000BF34B9 /* 2.0 */, ); diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m index db6a4950..b28e1ac7 100644 --- a/SDCAlertView/SDCViewController.m +++ b/SDCAlertView/SDCViewController.m @@ -39,7 +39,9 @@ - (void)presentNow { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; - [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:nil]]; + [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:^(SDCAlertAction *action) { + NSLog(@"%@", action.title); + }]]; [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { NSLog(@"%@", action.title); }]]; @@ -49,9 +51,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath }]; [ac presentWithCompletion:^{ - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [ac.actions.firstObject setEnabled:NO]; - }); + NSLog(@"Presented"); }]; // [self presentNow]; diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 89e20ac7..7b87f8bc 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -15,7 +15,8 @@ typedef NS_ENUM(NSInteger, SDCAlertActionStyle) { }; typedef NS_ENUM(NSInteger, SDCAlertControllerStyle) { - SDCAlertControllerStyleAlert = UIAlertControllerStyleAlert + SDCAlertControllerStyleAlert = UIAlertControllerStyleAlert, + SDCAlertControllerStyleLegacyAlert }; typedef NS_ENUM(NSInteger, SDCAlertControllerActionLayout) { @@ -34,6 +35,7 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerActionLayout) { @property (nonatomic, readonly) SDCAlertActionStyle style; @property (nonatomic, getter=isEnabled) BOOL enabled; +@property (nonatomic, readonly) void (^handler)(SDCAlertAction *action); @end @@ -62,23 +64,26 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerActionLayout) { @property (nonatomic, readonly) UIView *contentView; @property (nonatomic, readonly) SDCAlertControllerStyle preferredStyle; -- (void)applyVisualStyle:(id)visualStyle; +@property (nonatomic, strong) id visualStyle; @property (nonatomic, copy) BOOL (^shouldDismissBlock)(SDCAlertAction *action); @end -@interface SDCAlertController (Transitioning) +@interface SDCAlertController (Presentation) -- (void)present; - (void)presentWithCompletion:(void(^)(void))completion; -- (void)presentFromViewController:(UIViewController *)viewController completionHandler:(void(^)(void))completion; - -- (void)dismiss; - (void)dismissWithCompletion:(void(^)(void))completion; @end +@class SDCAlertView; + +@interface SDCAlertController (Legacy) +@property (nonatomic, readonly) BOOL usesLegacyAlert; +@property (nonatomic, readonly) SDCAlertView *legacyAlertView; +@end + @interface SDCAlertController (Convenience) + (instancetype)showAlertControllerWithTitle:(NSString *)title message:(NSString *)message; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index e5894e6e..676858aa 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -13,20 +13,22 @@ #import "SDCAlertControllerView.h" #import "SDCAlertControllerDefaultVisualStyle.h" #import "SDCIntrinsicallySizedView.h" +#import "SDCAlertView.h" #import "UIView+SDCAutoLayout.h" #import "UIViewController+Current.h" @interface SDCAlertAction (Private) -@property (nonatomic, copy) void (^handler)(SDCAlertAction *); +@property (nonatomic, copy) void (^handler)(SDCAlertAction *action); @end @interface SDCAlertController () +@property (nonatomic) SDCAlertControllerStyle preferredStyle; @property (nonatomic, strong) NSMutableArray *mutableActions; @property (nonatomic, strong) NSMutableArray *mutableTextFields; @property (nonatomic, strong) id transitioningDelegate; -@property (nonatomic, strong) id visualStyle; @property (nonatomic, strong) SDCAlertControllerView *alert; +@property (nonatomic, strong) SDCAlertView *legacyAlertView; @property (nonatomic) BOOL didAssignFirstResponder; @property (nonatomic, getter=isPresentingAlert) BOOL presentingAlert; @end @@ -49,18 +51,15 @@ - (instancetype)initWithStyle:(SDCAlertControllerStyle)style { self = [super init]; if (self) { - NSAssert(style == SDCAlertControllerStyleAlert, @"Only SDCAlertControllerStyleAlert is supported by %@", NSStringFromClass([self class])); - _mutableActions = [NSMutableArray array]; _mutableTextFields = [NSMutableArray array]; + _preferredStyle = style; _visualStyle = [[SDCAlertControllerDefaultVisualStyle alloc] init]; _actionLayout = SDCAlertControllerActionLayoutAutomatic; self.modalPresentationStyle = UIModalPresentationCustom; self.transitioningDelegate = [[SDCAlertControllerTransitioningDelegate alloc] init]; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardUpdate:) name:UIKeyboardWillChangeFrameNotification object:nil]; } return self; @@ -93,12 +92,26 @@ - (instancetype)initWithAttributedTitle:(NSAttributedString *)attributedTitle return self; } + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } #pragma mark - Alert View +- (SDCAlertView *)legacyAlertView { + if (!_legacyAlertView && self.usesLegacyAlert) { + _legacyAlertView = [SDCAlertView alertViewWithAlertController:self]; + } + return _legacyAlertView; +} + +- (BOOL)usesLegacyAlert { + return + self.preferredStyle == SDCAlertControllerStyleLegacyAlert || + ![NSProcessInfo instancesRespondToSelector:@selector(isOperatingSystemAtLeastVersion:)]; +} + - (void)setTitle:(NSString *)title { [super setTitle:title]; self.alert.title = [[NSAttributedString alloc] initWithString:title]; @@ -139,6 +152,8 @@ - (UIView *)contentView { - (void)viewDidLoad { [super viewDidLoad]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardUpdate:) name:UIKeyboardWillChangeFrameNotification object:nil]; + self.alert.visualStyle = self.visualStyle; self.alert.actions = self.actions; self.alert.actionLayout = self.actionLayout; @@ -170,16 +185,6 @@ - (void)viewDidAppear:(BOOL)animated { self.presentingAlert = NO; } -#pragma mark - Style - -- (SDCAlertControllerStyle)preferredStyle { - return SDCAlertControllerStyleAlert; -} - -- (void)applyVisualStyle:(id)visualStyle { - _visualStyle = visualStyle; -} - #pragma mark - Alert Actions - (void)addAction:(SDCAlertAction *)action { @@ -236,23 +241,20 @@ - (void)keyboardUpdate:(NSNotification *)notification { @implementation SDCAlertController (Presentation) -- (void)present { - [self presentWithCompletion:nil]; -} - - (void)presentWithCompletion:(void(^)(void))completion { - UIViewController *currentViewController = [UIViewController sdc_currentViewController]; - [self presentFromViewController:currentViewController completionHandler:completion]; + if (self.usesLegacyAlert) { + self.legacyAlertView.didPresentHandler = completion; + [self.legacyAlertView show]; + } else { + UIViewController *currentViewController = [UIViewController sdc_currentViewController]; + [self presentFromViewController:currentViewController completionHandler:completion]; + } } - (void)presentFromViewController:(UIViewController *)viewController completionHandler:(void (^)(void))completionHandler { [viewController presentViewController:self animated:YES completion:completionHandler]; } -- (void)dismiss { - [self dismissWithCompletion:nil]; -} - - (void)dismissWithCompletion:(void (^)(void))completion { [self.presentingViewController dismissViewControllerAnimated:YES completion:completion]; } @@ -277,7 +279,7 @@ + (instancetype)showAlertControllerWithTitle:(NSString *)title message:(NSString [controller.contentView addSubview:subview]; } - [controller present]; + [controller presentWithCompletion:nil]; return controller; } diff --git a/SDCAlertView/Source/SDCAlertView.h b/SDCAlertView/Source/SDCAlertView.h index 777ed015..3704a2ec 100644 --- a/SDCAlertView/Source/SDCAlertView.h +++ b/SDCAlertView/Source/SDCAlertView.h @@ -88,6 +88,9 @@ typedef NS_ENUM(NSInteger, SDCAlertViewStyle) { * meansthat if the delegate is set, the block will NOT be executed. */ +/// Alternative property for \c didPresentAlertView: +@property (nonatomic, copy) void (^didPresentHandler)(); + /// Alternative property for \c alertView:clickedButtonAtIndex: @property (nonatomic, copy) void (^clickedButtonHandler)(NSInteger buttonIndex); @@ -215,6 +218,11 @@ typedef NS_ENUM(NSInteger, SDCAlertViewStyle) { @end +@class SDCAlertController; +@interface SDCAlertView (SDCAlertController) ++ (instancetype)alertViewWithAlertController:(SDCAlertController *)alertController; +@end + @interface UIColor (SDCAlertViewColors) + (UIColor *)sdc_alertSeparatorColor; + (UIColor *)sdc_textFieldBackgroundViewColor; diff --git a/SDCAlertView/Source/SDCAlertView.m b/SDCAlertView/Source/SDCAlertView.m index 2c3cfae7..92265ce6 100644 --- a/SDCAlertView/Source/SDCAlertView.m +++ b/SDCAlertView/Source/SDCAlertView.m @@ -13,6 +13,8 @@ #import "SDCAlertViewBackgroundView.h" #import "SDCAlertViewContentView.h" +#import "SDCAlertController.h" + #import "UIView+SDCAutoLayout.h" #import "UIView+Parallax.h" @@ -136,6 +138,10 @@ - (void)willBePresented { - (void)wasPresented { if ([self.delegate respondsToSelector:@selector(didPresentAlertView:)]) [self.delegate didPresentAlertView:self]; + + if (self.didPresentHandler) { + self.didPresentHandler(); + } } #pragma mark - Dismissing @@ -485,6 +491,60 @@ - (void)setButtonTextColor:(UIColor *)buttonTextColor { @end +@implementation SDCAlertView (SDCAlertController) + ++ (instancetype)alertViewWithAlertController:(SDCAlertController *)alertController { + NSString *cancelButtonTitle = [alertController.actions.firstObject title]; + SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:alertController.title + message:alertController.message + delegate:alertController + cancelButtonTitle:cancelButtonTitle + otherButtonTitles:nil]; + [alertController.actions enumerateObjectsUsingBlock:^(SDCAlertView *action, NSUInteger idx, BOOL *stop) { + if (idx > 0) { + // Skip the first one, that's the cancel button and has already been added + [alert addButtonWithTitle:action.title]; + } + }]; + + if (alertController.attributedTitle) { + alert.attributedTitle = alertController.attributedTitle; + } + + if (alertController.attributedMessage) { + alert.attributedMessage = alertController.attributedMessage; + } + + alert.alertViewStyle = SDCAlertViewStyleDefault; + + if (alertController.textFields.count == 1) { + if ([alertController.textFields.firstObject isSecureTextEntry]) { + alert.alertViewStyle = SDCAlertViewStyleSecureTextInput; + } else { + alert.alertViewStyle = SDCAlertViewStylePlainTextInput; + } + } else if (alertController.textFields.count >= 2) { + alert.alertViewStyle = SDCAlertViewStyleLoginAndPasswordInput; + } + + [alertController.contentView.subviews enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) { + [alert.contentView addSubview:subview]; + }]; + + alert.alwaysShowsButtonsVertically = (alertController.actionLayout == SDCAlertControllerActionLayoutVertical); + + alert.didDismissHandler = ^(NSInteger buttonIndex) { + SDCAlertAction *action = alertController.actions[buttonIndex]; + if (action.handler) { + action.handler(action); + } + }; + + return alert; +} + +@end + @implementation UIColor (SDCAlertViewColors) + (UIColor *)sdc_alertSeparatorColor { From 3cb4b06d86d5ac6d1bd4287b6208857ccb41c7ad Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 6 Oct 2014 20:39:38 -0700 Subject: [PATCH 59/76] Create UI for new demo project --- SDCAlertView.xcodeproj/project.pbxproj | 26 +- .../contents.xcworkspacedata | 11 +- SDCAlertView/AlertDemo.storyboard | 264 ++++++++++++++++++ SDCAlertView/Base.lproj/iPhone.storyboard | 214 -------------- SDCAlertView/SDCAlertView-Info.plist | 4 +- SDCAlertView/Source/SDCAlertController.h | 2 +- SDCAlertView/Source/SDCDemoViewController.h | 13 + SDCAlertView/Source/SDCDemoViewController.m | 19 ++ SDCAlertView/iPad.storyboard | 213 -------------- 9 files changed, 319 insertions(+), 447 deletions(-) create mode 100644 SDCAlertView/AlertDemo.storyboard delete mode 100644 SDCAlertView/Base.lproj/iPhone.storyboard create mode 100644 SDCAlertView/Source/SDCDemoViewController.h create mode 100644 SDCAlertView/Source/SDCDemoViewController.m delete mode 100644 SDCAlertView/iPad.storyboard diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index 0263dae9..e8a4559c 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -16,7 +16,6 @@ D25B3CB217ECE7A6004B32A2 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D25B3CB017ECE7A6004B32A2 /* InfoPlist.strings */; }; D25B3CB417ECE7A6004B32A2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D25B3CB317ECE7A6004B32A2 /* main.m */; }; D25B3CB817ECE7A6004B32A2 /* SDCAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D25B3CB717ECE7A6004B32A2 /* SDCAppDelegate.m */; }; - D25B3CBB17ECE7A6004B32A2 /* iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D25B3CB917ECE7A6004B32A2 /* iPhone.storyboard */; }; D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D25B3CBD17ECE7A6004B32A2 /* SDCViewController.m */; }; D25B3CC017ECE7A6004B32A2 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D25B3CBF17ECE7A6004B32A2 /* Images.xcassets */; }; D25B3CC717ECE7A6004B32A2 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D25B3CC617ECE7A6004B32A2 /* XCTest.framework */; }; @@ -32,6 +31,7 @@ D2666A4019CFDE2800167157 /* SDCAlertControllerView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A3F19CFDE2800167157 /* SDCAlertControllerView.m */; }; D2666A4319CFDF6700167157 /* SDCAlertControllerScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4219CFDF6700167157 /* SDCAlertControllerScrollView.m */; }; D2666A4619CFE0F900167157 /* SDCAlertLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4519CFE0F900167157 /* SDCAlertLabel.m */; }; + D28B5B5519E3863B00B76354 /* AlertDemo.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D28B5B5419E3863B00B76354 /* AlertDemo.storyboard */; }; D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */ = {isa = PBXBuildFile; fileRef = D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */; }; D2988E0319D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = D2988E0219D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m */; }; D2A520181840176300837A1A /* SDCAlertView.podspec in Resources */ = {isa = PBXBuildFile; fileRef = D2A520171840176300837A1A /* SDCAlertView.podspec */; }; @@ -39,9 +39,9 @@ D2A6A0DB19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */; }; D2A6F1C519D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */; }; D2AE983119DFBDF50083AB0C /* UIViewController+Current.m in Sources */ = {isa = PBXBuildFile; fileRef = D2AE983019DFBDF50083AB0C /* UIViewController+Current.m */; }; - D2BD0CC418FEB2C400520E33 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC318FEB2C400520E33 /* iPad.storyboard */; }; D2BD0CC618FED65700520E33 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = D2BD0CC518FED65700520E33 /* CHANGELOG.md */; }; D2CABE9519E1ECFE00CA1A89 /* UIView+Parallax.m in Sources */ = {isa = PBXBuildFile; fileRef = D2CABE9419E1ECFE00CA1A89 /* UIView+Parallax.m */; }; + D2CAD11719E38FE7005E1C33 /* SDCDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2CAD11619E38FE7005E1C33 /* SDCDemoViewController.m */; }; D2D5A77019D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D2D5A76F19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m */; }; D2F8345918EF2893000BB281 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = D2F8345718EF2887000BB281 /* Podfile */; }; D2F9D2BD18400CD300F85B10 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = D2F9D2BC18400CD200F85B10 /* README.md */; }; @@ -77,7 +77,6 @@ D25B3CB517ECE7A6004B32A2 /* SDCAlertView-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SDCAlertView-Prefix.pch"; sourceTree = ""; }; D25B3CB617ECE7A6004B32A2 /* SDCAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCAppDelegate.h; sourceTree = ""; }; D25B3CB717ECE7A6004B32A2 /* SDCAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDCAppDelegate.m; sourceTree = ""; }; - D25B3CBA17ECE7A6004B32A2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/iPhone.storyboard; sourceTree = ""; }; D25B3CBC17ECE7A6004B32A2 /* SDCViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCViewController.h; sourceTree = ""; }; D25B3CBD17ECE7A6004B32A2 /* SDCViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDCViewController.m; sourceTree = ""; }; D25B3CBF17ECE7A6004B32A2 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; @@ -103,6 +102,7 @@ D2666A4419CFE0F900167157 /* SDCAlertLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertLabel.h; sourceTree = ""; }; D2666A4519CFE0F900167157 /* SDCAlertLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertLabel.m; sourceTree = ""; }; D268093118F845420001B7E9 /* SDCAlertViewTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCAlertViewTransitioning.h; sourceTree = ""; }; + D28B5B5419E3863B00B76354 /* AlertDemo.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = AlertDemo.storyboard; sourceTree = ""; }; D294876A18D631B700E3D967 /* SDCIntrinsicallySizedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCIntrinsicallySizedView.h; sourceTree = ""; }; D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCIntrinsicallySizedView.m; sourceTree = ""; }; D2988E0119D794C100140116 /* SDCAlertControllerDefaultVisualStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerDefaultVisualStyle.h; sourceTree = ""; }; @@ -117,10 +117,11 @@ D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertTextFieldTableViewCell.m; sourceTree = ""; }; D2AE982F19DFBDF50083AB0C /* UIViewController+Current.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Current.h"; sourceTree = ""; }; D2AE983019DFBDF50083AB0C /* UIViewController+Current.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Current.m"; sourceTree = ""; }; - D2BD0CC318FEB2C400520E33 /* iPad.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = iPad.storyboard; sourceTree = ""; }; D2BD0CC518FED65700520E33 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CHANGELOG.md; sourceTree = ""; }; D2CABE9319E1ECFE00CA1A89 /* UIView+Parallax.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Parallax.h"; sourceTree = ""; }; D2CABE9419E1ECFE00CA1A89 /* UIView+Parallax.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Parallax.m"; sourceTree = ""; }; + D2CAD11519E38FE7005E1C33 /* SDCDemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDCDemoViewController.h; path = Source/SDCDemoViewController.h; sourceTree = ""; }; + D2CAD11619E38FE7005E1C33 /* SDCDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDCDemoViewController.m; path = Source/SDCDemoViewController.m; sourceTree = ""; }; D2D5A76E19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertControllerTextFieldViewController.h; sourceTree = ""; }; D2D5A76F19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertControllerTextFieldViewController.m; sourceTree = ""; }; D2F8345718EF2887000BB281 /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = ""; }; @@ -202,8 +203,9 @@ D2F8347218EF2C09000BB281 /* Source */, D25B3CB617ECE7A6004B32A2 /* SDCAppDelegate.h */, D25B3CB717ECE7A6004B32A2 /* SDCAppDelegate.m */, - D25B3CB917ECE7A6004B32A2 /* iPhone.storyboard */, - D2BD0CC318FEB2C400520E33 /* iPad.storyboard */, + D28B5B5419E3863B00B76354 /* AlertDemo.storyboard */, + D2CAD11519E38FE7005E1C33 /* SDCDemoViewController.h */, + D2CAD11619E38FE7005E1C33 /* SDCDemoViewController.m */, D25B3CBC17ECE7A6004B32A2 /* SDCViewController.h */, D25B3CBD17ECE7A6004B32A2 /* SDCViewController.m */, D25B3CBF17ECE7A6004B32A2 /* Images.xcassets */, @@ -385,12 +387,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + D28B5B5519E3863B00B76354 /* AlertDemo.storyboard in Resources */, D25B3CC017ECE7A6004B32A2 /* Images.xcassets in Resources */, D25B3CB217ECE7A6004B32A2 /* InfoPlist.strings in Resources */, D2F9D2BD18400CD300F85B10 /* README.md in Resources */, D2A520181840176300837A1A /* SDCAlertView.podspec in Resources */, - D2BD0CC418FEB2C400520E33 /* iPad.storyboard in Resources */, - D25B3CBB17ECE7A6004B32A2 /* iPhone.storyboard in Resources */, D2F8345918EF2893000BB281 /* Podfile in Resources */, D2BD0CC618FED65700520E33 /* CHANGELOG.md in Resources */, D2F9D2BF18400DAF00F85B10 /* LICENSE in Resources */, @@ -475,6 +476,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D2CAD11719E38FE7005E1C33 /* SDCDemoViewController.m in Sources */, D2A5E0D119D3D6A90034B709 /* SDCAlertCollectionViewCell.m in Sources */, D2A6F1C519D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m in Sources */, D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */, @@ -527,14 +529,6 @@ name = InfoPlist.strings; sourceTree = ""; }; - D25B3CB917ECE7A6004B32A2 /* iPhone.storyboard */ = { - isa = PBXVariantGroup; - children = ( - D25B3CBA17ECE7A6004B32A2 /* Base */, - ); - name = iPhone.storyboard; - sourceTree = ""; - }; D25B3CCF17ECE7A6004B32A2 /* InfoPlist.strings */ = { isa = PBXVariantGroup; children = ( diff --git a/SDCAlertView.xcworkspace/contents.xcworkspacedata b/SDCAlertView.xcworkspace/contents.xcworkspacedata index 313b4403..d6c9db23 100644 --- a/SDCAlertView.xcworkspace/contents.xcworkspacedata +++ b/SDCAlertView.xcworkspace/contents.xcworkspacedata @@ -1 +1,10 @@ - \ No newline at end of file + + + + + + + diff --git a/SDCAlertView/AlertDemo.storyboard b/SDCAlertView/AlertDemo.storyboard new file mode 100644 index 00000000..8fb6b89d --- /dev/null +++ b/SDCAlertView/AlertDemo.storyboard @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SDCAlertView/Base.lproj/iPhone.storyboard b/SDCAlertView/Base.lproj/iPhone.storyboard deleted file mode 100644 index 5129ac59..00000000 --- a/SDCAlertView/Base.lproj/iPhone.storyboard +++ /dev/null @@ -1,214 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SDCAlertView/SDCAlertView-Info.plist b/SDCAlertView/SDCAlertView-Info.plist index 7c83395d..5397869f 100644 --- a/SDCAlertView/SDCAlertView-Info.plist +++ b/SDCAlertView/SDCAlertView-Info.plist @@ -25,9 +25,9 @@ LSRequiresIPhoneOS UIMainStoryboardFile - iPhone + AlertDemo UIMainStoryboardFile~ipad - iPad + AlertDemo UIRequiredDeviceCapabilities armv7 diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 7b87f8bc..b5618177 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -35,7 +35,7 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerActionLayout) { @property (nonatomic, readonly) SDCAlertActionStyle style; @property (nonatomic, getter=isEnabled) BOOL enabled; -@property (nonatomic, readonly) void (^handler)(SDCAlertAction *action); +@property (nonatomic, copy, readonly) void (^handler)(SDCAlertAction *action); @end diff --git a/SDCAlertView/Source/SDCDemoViewController.h b/SDCAlertView/Source/SDCDemoViewController.h new file mode 100644 index 00000000..8806c8cb --- /dev/null +++ b/SDCAlertView/Source/SDCDemoViewController.h @@ -0,0 +1,13 @@ +// +// SDCDemoViewController.h +// SDCAlertView +// +// Created by Scott Berrevoets on 10/6/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import + +@interface SDCDemoViewController : UITableViewController + +@end diff --git a/SDCAlertView/Source/SDCDemoViewController.m b/SDCAlertView/Source/SDCDemoViewController.m new file mode 100644 index 00000000..083aa665 --- /dev/null +++ b/SDCAlertView/Source/SDCDemoViewController.m @@ -0,0 +1,19 @@ +// +// SDCDemoViewController.m +// SDCAlertView +// +// Created by Scott Berrevoets on 10/6/14. +// Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. +// + +#import "SDCDemoViewController.h" + +@implementation SDCDemoViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + self.tableView.rowHeight = 44; +} + + +@end diff --git a/SDCAlertView/iPad.storyboard b/SDCAlertView/iPad.storyboard deleted file mode 100644 index 61266a6e..00000000 --- a/SDCAlertView/iPad.storyboard +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 041e03e673d3f258b1531cfac5de645f33290ad0 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 6 Oct 2014 22:07:22 -0700 Subject: [PATCH 60/76] Create basic demo --- SDCAlertView.xcodeproj/project.pbxproj | 4 ++ SDCAlertView/AlertDemo.storyboard | 53 +++++++++++++- SDCAlertView/Launch Screen.xib | 44 ++++++++++++ SDCAlertView/SDCAlertView-Info.plist | 2 + SDCAlertView/Source/SDCDemoViewController.m | 78 +++++++++++++++++++++ 5 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 SDCAlertView/Launch Screen.xib diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index e8a4559c..bf8bc9dc 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ D2666A4019CFDE2800167157 /* SDCAlertControllerView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A3F19CFDE2800167157 /* SDCAlertControllerView.m */; }; D2666A4319CFDF6700167157 /* SDCAlertControllerScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4219CFDF6700167157 /* SDCAlertControllerScrollView.m */; }; D2666A4619CFE0F900167157 /* SDCAlertLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = D2666A4519CFE0F900167157 /* SDCAlertLabel.m */; }; + D268314919E3ABE2005FC8B0 /* Launch Screen.xib in Resources */ = {isa = PBXBuildFile; fileRef = D268314819E3ABE2005FC8B0 /* Launch Screen.xib */; }; D28B5B5519E3863B00B76354 /* AlertDemo.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D28B5B5419E3863B00B76354 /* AlertDemo.storyboard */; }; D294876C18D631B700E3D967 /* SDCIntrinsicallySizedView.m in Sources */ = {isa = PBXBuildFile; fileRef = D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */; }; D2988E0319D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = D2988E0219D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m */; }; @@ -102,6 +103,7 @@ D2666A4419CFE0F900167157 /* SDCAlertLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCAlertLabel.h; sourceTree = ""; }; D2666A4519CFE0F900167157 /* SDCAlertLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCAlertLabel.m; sourceTree = ""; }; D268093118F845420001B7E9 /* SDCAlertViewTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCAlertViewTransitioning.h; sourceTree = ""; }; + D268314819E3ABE2005FC8B0 /* Launch Screen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = "Launch Screen.xib"; sourceTree = ""; }; D28B5B5419E3863B00B76354 /* AlertDemo.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = AlertDemo.storyboard; sourceTree = ""; }; D294876A18D631B700E3D967 /* SDCIntrinsicallySizedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDCIntrinsicallySizedView.h; sourceTree = ""; }; D294876B18D631B700E3D967 /* SDCIntrinsicallySizedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDCIntrinsicallySizedView.m; sourceTree = ""; }; @@ -200,6 +202,7 @@ D25B3CAD17ECE7A6004B32A2 /* SDCAlertView */ = { isa = PBXGroup; children = ( + D268314819E3ABE2005FC8B0 /* Launch Screen.xib */, D2F8347218EF2C09000BB281 /* Source */, D25B3CB617ECE7A6004B32A2 /* SDCAppDelegate.h */, D25B3CB717ECE7A6004B32A2 /* SDCAppDelegate.m */, @@ -389,6 +392,7 @@ files = ( D28B5B5519E3863B00B76354 /* AlertDemo.storyboard in Resources */, D25B3CC017ECE7A6004B32A2 /* Images.xcassets in Resources */, + D268314919E3ABE2005FC8B0 /* Launch Screen.xib in Resources */, D25B3CB217ECE7A6004B32A2 /* InfoPlist.strings in Resources */, D2F9D2BD18400CD300F85B10 /* README.md in Resources */, D2A520181840176300837A1A /* SDCAlertView.podspec in Resources */, diff --git a/SDCAlertView/AlertDemo.storyboard b/SDCAlertView/AlertDemo.storyboard index 8fb6b89d..d041a933 100644 --- a/SDCAlertView/AlertDemo.storyboard +++ b/SDCAlertView/AlertDemo.storyboard @@ -87,6 +87,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -98,8 +131,11 @@ - + + + + - + - + - - - - - - - + + + + + + + + + + + + @@ -299,7 +298,7 @@ - + diff --git a/SDCAlertView/Source/SDCDemoViewController.m b/SDCAlertView/Source/SDCDemoViewController.m index 44b9bd64..e0336b9d 100644 --- a/SDCAlertView/Source/SDCDemoViewController.m +++ b/SDCAlertView/Source/SDCDemoViewController.m @@ -14,7 +14,7 @@ @interface SDCDemoViewController () @property (nonatomic, weak) IBOutlet UISegmentedControl *alertStyleControl; @property (nonatomic, weak) IBOutlet UITextField *titleTextField; @property (nonatomic, weak) IBOutlet UITextField *messageTextField; -@property (nonatomic, weak) IBOutlet UILabel *textFieldsLabel; +@property (nonatomic, weak) IBOutlet UITextField *textFieldsTextField; @property (nonatomic) NSInteger selectedContentViewIndex; @property (nonatomic, strong) UIView *contentView; @property (nonatomic, weak) IBOutlet UITextField *buttonsTextField; @@ -43,7 +43,7 @@ - (void)showAlertWithStyle:(SDCAlertControllerStyle)style { message:self.messageTextField.text preferredStyle:style]; - NSInteger textFields = self.textFieldsLabel.text.integerValue; + NSInteger textFields = self.textFieldsTextField.text.integerValue; for (NSInteger i = 0; i < textFields; i++) { [alert addTextFieldWithConfigurationHandler:nil]; } @@ -89,9 +89,4 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone]; } - -- (IBAction)textFieldStepperTapped:(UIStepper *)sender { - self.textFieldsLabel.text = [NSString stringWithFormat:@"%@", @(sender.value)]; -} - @end From c82cbee49849f8f7dc32a24f0f8cd25e61516dde Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 6 Oct 2014 22:32:48 -0700 Subject: [PATCH 63/76] Add contentView to demo alerts --- SDCAlertView/Source/SDCDemoViewController.m | 66 +++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/SDCAlertView/Source/SDCDemoViewController.m b/SDCAlertView/Source/SDCDemoViewController.m index e0336b9d..a56451ee 100644 --- a/SDCAlertView/Source/SDCDemoViewController.m +++ b/SDCAlertView/Source/SDCDemoViewController.m @@ -9,6 +9,9 @@ #import "SDCDemoViewController.h" #import "SDCAlertController.h" +#import + +@import MapKit; @interface SDCDemoViewController () @property (nonatomic, weak) IBOutlet UISegmentedControl *alertStyleControl; @@ -58,9 +61,72 @@ - (void)showAlertWithStyle:(SDCAlertControllerStyle)style { alert.actionLayout = self.buttonLayoutControl.selectedSegmentIndex; + if (self.selectedContentViewIndex > 0) { + [self addContentViewToAlert:alert]; + } + [alert presentWithCompletion:nil]; } +- (void)addContentViewToAlert:(SDCAlertController *)alert { + switch (self.selectedContentViewIndex) { + case 1: { + UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; + [spinner setTranslatesAutoresizingMaskIntoConstraints:NO]; + [spinner startAnimating]; + [alert.contentView addSubview:spinner]; + + [spinner sdc_horizontallyCenterInSuperview]; + [alert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[spinner]-(==20)-|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(spinner)]]; + + + break; + } case 2: { + UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; + progressView.progress = 0; + + [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateProgressView:) userInfo:progressView repeats:YES]; + + [progressView setTranslatesAutoresizingMaskIntoConstraints:NO]; + [alert.contentView addSubview:progressView]; + + [progressView sdc_pinWidthToWidthOfView:alert.contentView offset:-20]; + [progressView sdc_horizontallyCenterInSuperview]; + + [alert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[progressView]-|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(progressView)]]; + break; + } case 3: { + MKMapView *mapView = [[MKMapView alloc] init]; + [mapView setTranslatesAutoresizingMaskIntoConstraints:NO]; + + MKCoordinateRegion region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(37.3175, -122.041944), MKCoordinateSpanMake(.1, .1)); + [mapView setRegion:region animated:YES]; + [alert.contentView addSubview:mapView]; + + [mapView sdc_pinWidthToWidthOfView:alert.contentView]; + [mapView sdc_centerInSuperview]; + [mapView sdc_pinHeight:120]; + + break; + } + } +} + +- (void)updateProgressView:(NSTimer *)timer { + UIProgressView *progressView = [timer userInfo]; + + if (progressView.progress < 1) + progressView.progress += .05; + else + [timer invalidate]; +} + - (void)showSystemAlert { } From b891e572fc887cd1846a1b5028fb4199e85ea0b5 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 6 Oct 2014 22:47:51 -0700 Subject: [PATCH 64/76] Add content to view in a backwards compatible manner --- SDCAlertView/Source/SDCDemoViewController.m | 29 ++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/SDCAlertView/Source/SDCDemoViewController.m b/SDCAlertView/Source/SDCDemoViewController.m index a56451ee..40f0a3db 100644 --- a/SDCAlertView/Source/SDCDemoViewController.m +++ b/SDCAlertView/Source/SDCDemoViewController.m @@ -9,6 +9,7 @@ #import "SDCDemoViewController.h" #import "SDCAlertController.h" +#import "SDCAlertView.h" #import @import MapKit; @@ -61,23 +62,27 @@ - (void)showAlertWithStyle:(SDCAlertControllerStyle)style { alert.actionLayout = self.buttonLayoutControl.selectedSegmentIndex; - if (self.selectedContentViewIndex > 0) { - [self addContentViewToAlert:alert]; + if (self.selectedContentViewIndex > 0 && alert.usesLegacyAlert) { + [self addContentToView:alert.legacyAlertView.contentView]; + [alert presentWithCompletion:nil]; + } else if (self.selectedContentViewIndex > 0) { + [self addContentToView:alert.contentView]; + [alert presentWithCompletion:nil]; + } else { + [alert presentWithCompletion:nil]; } - - [alert presentWithCompletion:nil]; } -- (void)addContentViewToAlert:(SDCAlertController *)alert { +- (void)addContentToView:(UIView *)contentView { switch (self.selectedContentViewIndex) { case 1: { UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [spinner setTranslatesAutoresizingMaskIntoConstraints:NO]; [spinner startAnimating]; - [alert.contentView addSubview:spinner]; + [contentView addSubview:spinner]; [spinner sdc_horizontallyCenterInSuperview]; - [alert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[spinner]-(==20)-|" + [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[spinner]-(==20)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(spinner)]]; @@ -91,12 +96,12 @@ - (void)addContentViewToAlert:(SDCAlertController *)alert { [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateProgressView:) userInfo:progressView repeats:YES]; [progressView setTranslatesAutoresizingMaskIntoConstraints:NO]; - [alert.contentView addSubview:progressView]; + [contentView addSubview:progressView]; - [progressView sdc_pinWidthToWidthOfView:alert.contentView offset:-20]; + [progressView sdc_pinWidthToWidthOfView:contentView offset:-20]; [progressView sdc_horizontallyCenterInSuperview]; - [alert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[progressView]-|" + [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[progressView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(progressView)]]; @@ -107,9 +112,9 @@ - (void)addContentViewToAlert:(SDCAlertController *)alert { MKCoordinateRegion region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(37.3175, -122.041944), MKCoordinateSpanMake(.1, .1)); [mapView setRegion:region animated:YES]; - [alert.contentView addSubview:mapView]; + [contentView addSubview:mapView]; - [mapView sdc_pinWidthToWidthOfView:alert.contentView]; + [mapView sdc_pinWidthToWidthOfView:contentView]; [mapView sdc_centerInSuperview]; [mapView sdc_pinHeight:120]; From 36d53b7f8cb5aa5f92c5ae48e2796d0d326d7c0c Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 13 Oct 2014 19:48:27 -0700 Subject: [PATCH 65/76] Show system alert when selected --- SDCAlertView/Source/SDCDemoViewController.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/SDCAlertView/Source/SDCDemoViewController.m b/SDCAlertView/Source/SDCDemoViewController.m index 40f0a3db..a904cfc9 100644 --- a/SDCAlertView/Source/SDCDemoViewController.m +++ b/SDCAlertView/Source/SDCDemoViewController.m @@ -133,7 +133,24 @@ - (void)updateProgressView:(NSTimer *)timer { } - (void)showSystemAlert { + UIAlertController *alert = [UIAlertController alertControllerWithTitle:self.titleTextField.text + message:self.messageTextField.text + preferredStyle:UIAlertControllerStyleAlert]; + NSInteger textFields = self.textFieldsTextField.text.integerValue; + for (NSInteger i = 0; i < textFields; i++) { + [alert addTextFieldWithConfigurationHandler:nil]; + } + + NSInteger buttons = self.buttonsTextField.text.integerValue; + for (NSInteger i = 0; i < buttons; i++) { + UIAlertAction *action = [UIAlertAction actionWithTitle:[NSString stringWithFormat:@"Button %@", @(i)] + style:UIAlertActionStyleDefault + handler:nil]; + [alert addAction:action]; + } + + [self presentViewController:alert animated:YES completion:nil]; } -(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath { From 91cf24a9a06abcffef44bce4a33783e4b5d3098a Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 13 Oct 2014 19:53:29 -0700 Subject: [PATCH 66/76] Remove old demo view controller --- SDCAlertView.xcodeproj/project.pbxproj | 6 - SDCAlertView/SDCViewController.h | 13 -- SDCAlertView/SDCViewController.m | 196 ------------------------- 3 files changed, 215 deletions(-) delete mode 100644 SDCAlertView/SDCViewController.h delete mode 100644 SDCAlertView/SDCViewController.m diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index bf8bc9dc..f6d494d3 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -16,7 +16,6 @@ D25B3CB217ECE7A6004B32A2 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D25B3CB017ECE7A6004B32A2 /* InfoPlist.strings */; }; D25B3CB417ECE7A6004B32A2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D25B3CB317ECE7A6004B32A2 /* main.m */; }; D25B3CB817ECE7A6004B32A2 /* SDCAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D25B3CB717ECE7A6004B32A2 /* SDCAppDelegate.m */; }; - D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D25B3CBD17ECE7A6004B32A2 /* SDCViewController.m */; }; D25B3CC017ECE7A6004B32A2 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D25B3CBF17ECE7A6004B32A2 /* Images.xcassets */; }; D25B3CC717ECE7A6004B32A2 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D25B3CC617ECE7A6004B32A2 /* XCTest.framework */; }; D25B3CC817ECE7A6004B32A2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D25B3CA717ECE7A6004B32A2 /* Foundation.framework */; }; @@ -78,8 +77,6 @@ D25B3CB517ECE7A6004B32A2 /* SDCAlertView-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SDCAlertView-Prefix.pch"; sourceTree = ""; }; D25B3CB617ECE7A6004B32A2 /* SDCAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCAppDelegate.h; sourceTree = ""; }; D25B3CB717ECE7A6004B32A2 /* SDCAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDCAppDelegate.m; sourceTree = ""; }; - D25B3CBC17ECE7A6004B32A2 /* SDCViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDCViewController.h; sourceTree = ""; }; - D25B3CBD17ECE7A6004B32A2 /* SDCViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDCViewController.m; sourceTree = ""; }; D25B3CBF17ECE7A6004B32A2 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; D25B3CC517ECE7A6004B32A2 /* SDCAlertViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SDCAlertViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; D25B3CC617ECE7A6004B32A2 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; @@ -209,8 +206,6 @@ D28B5B5419E3863B00B76354 /* AlertDemo.storyboard */, D2CAD11519E38FE7005E1C33 /* SDCDemoViewController.h */, D2CAD11619E38FE7005E1C33 /* SDCDemoViewController.m */, - D25B3CBC17ECE7A6004B32A2 /* SDCViewController.h */, - D25B3CBD17ECE7A6004B32A2 /* SDCViewController.m */, D25B3CBF17ECE7A6004B32A2 /* Images.xcassets */, D25B3CAE17ECE7A6004B32A2 /* Supporting Files */, ); @@ -483,7 +478,6 @@ D2CAD11719E38FE7005E1C33 /* SDCDemoViewController.m in Sources */, D2A5E0D119D3D6A90034B709 /* SDCAlertCollectionViewCell.m in Sources */, D2A6F1C519D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m in Sources */, - D25B3CBE17ECE7A6004B32A2 /* SDCViewController.m in Sources */, D25B3CB417ECE7A6004B32A2 /* main.m in Sources */, D2D5A77019D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m in Sources */, D259FC1519CEB0EB00BA6B36 /* SDCAlertControllerTransition.m in Sources */, diff --git a/SDCAlertView/SDCViewController.h b/SDCAlertView/SDCViewController.h deleted file mode 100644 index f06fc392..00000000 --- a/SDCAlertView/SDCViewController.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// SDCViewController.h -// SDCAlertView -// -// Created by Scott Berrevoets on 9/20/13. -// Copyright (c) 2013 Scotty Doesn't Code. All rights reserved. -// - -#import - -@interface SDCViewController : UITableViewController - -@end diff --git a/SDCAlertView/SDCViewController.m b/SDCAlertView/SDCViewController.m deleted file mode 100644 index b28e1ac7..00000000 --- a/SDCAlertView/SDCViewController.m +++ /dev/null @@ -1,196 +0,0 @@ -// -// SDCViewController.m -// SDCAlertView -// -// Created by Scott Berrevoets on 9/20/13. -// Copyright (c) 2013 Scotty Doesn't Code. All rights reserved. -// - -@import MapKit; - -#import "SDCViewController.h" - -#import "SDCAlertView.h" -#import "UIView+SDCAutoLayout.h" - -#import "SDCAlertController.h" -#import "SDCAlertControllerTransition.h" - -@interface SDCViewController () -@end - -@implementation SDCViewController - -- (void)presentNow { - - - UIAlertController *b = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert]; - [b addAction:[UIAlertAction actionWithTitle:@"Button 2" style:UIAlertActionStyleDefault handler:nil]]; - [b addAction:[UIAlertAction actionWithTitle:@"Button 33??" style:UIAlertActionStyleCancel handler:nil]]; - - [b addTextFieldWithConfigurationHandler:nil]; - //[b addTextFieldWithConfigurationHandler:nil]; - - [self presentViewController:b animated:YES completion:^{ - //NSLog(@"%@", [b valueForKey:@"styleProvider"]); - }]; -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - if (indexPath.section == 0) { - SDCAlertController *ac = [SDCAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; - [ac addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleDestructive handler:^(SDCAlertAction *action) { - NSLog(@"%@", action.title); - }]]; - [ac addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { - NSLog(@"%@", action.title); - }]]; - - [ac addTextFieldWithConfigurationHandler:^(UITextField *textField) { - textField.delegate = self; - }]; - - [ac presentWithCompletion:^{ - NSLog(@"Presented"); - }]; -// [self presentNow]; - - } else if (indexPath.section == 1) { - if (indexPath.row == 0) { - SDCAlertView *a = [[SDCAlertView alloc] initWithTitle:@"Title" - message:@"This is a message" - delegate:self - cancelButtonTitle:@"Cancel" - otherButtonTitles:@"OK", nil]; - [a show]; - } else if (indexPath.row == 1) { - [[[SDCAlertView alloc] initWithTitle:@"Title" - message:@"This is a message" - delegate:nil - cancelButtonTitle:@"Cancel" - otherButtonTitles:@"OK", @"Whatever", nil] show]; - } else if (indexPath.row == 2) { - SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Title" - message:@"This is a message" - delegate:nil - cancelButtonTitle:nil - otherButtonTitles:@"OK", nil]; - alert.alertViewStyle = SDCAlertViewStylePlainTextInput; - - [alert show]; - } else if (indexPath.row == 3) { - SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Title" - message:@"This is a message" - delegate:nil - cancelButtonTitle:nil - otherButtonTitles:@"OK", nil]; - alert.alertViewStyle = SDCAlertViewStyleLoginAndPasswordInput; - - [alert show]; - } - } else if (indexPath.section == 2) { - if (indexPath.row == 0) { - - SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Please wait..." - message:@"Please wait until we're done doing what we're doing" - delegate:nil - cancelButtonTitle:nil - otherButtonTitles:@"OK", nil]; - - UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; - progressView.progress = 0; - - [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateProgressView:) userInfo:progressView repeats:YES]; - - [progressView setTranslatesAutoresizingMaskIntoConstraints:NO]; - [alert.contentView addSubview:progressView]; - - [progressView sdc_pinWidthToWidthOfView:alert.contentView offset:-20]; - [progressView sdc_horizontallyCenterInSuperview]; - - [alert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[progressView]|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(progressView)]]; - - [alert show]; - } else if (indexPath.row == 1) { - SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Contacting Server" - message:@"We're doing some network stuff. Hang on..." - delegate:nil - cancelButtonTitle:@"OK" - otherButtonTitles:nil]; - - UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; - [spinner setTranslatesAutoresizingMaskIntoConstraints:NO]; - [spinner startAnimating]; - [alert.contentView addSubview:spinner]; - - [spinner sdc_centerInSuperview]; - - [alert show]; - } else if (indexPath.row == 2) { - SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Cupertino, CA" - message:nil - delegate:nil - cancelButtonTitle:@"OK" - otherButtonTitles:nil]; - MKMapView *mapView = [[MKMapView alloc] init]; - [mapView setTranslatesAutoresizingMaskIntoConstraints:NO]; - - MKCoordinateRegion region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(37.3175, -122.041944), MKCoordinateSpanMake(.1, .1)); - [mapView setRegion:region animated:YES]; - [alert.contentView addSubview:mapView]; - - [mapView sdc_pinWidthToWidthOfView:alert.contentView]; - [mapView sdc_centerInSuperview]; - [mapView sdc_pinHeight:120]; - - [alert show]; - } - } - - [tableView deselectRowAtIndexPath:indexPath animated:YES]; -} - -- (BOOL)textFieldShouldReturn:(UITextField *)textField { - [textField resignFirstResponder]; - return YES; -} - -- (void)updateProgressView:(NSTimer *)timer { - UIProgressView *progressView = [timer userInfo]; - - if (progressView.progress < 1) - progressView.progress += .05; - else - [timer invalidate]; -} - -- (IBAction)changeAppearance:(UISegmentedControl *)sender { - if (sender.selectedSegmentIndex == 0) { - [[SDCAlertView appearance] setTitleLabelFont:[UIFont boldSystemFontOfSize:17]]; - [[SDCAlertView appearance] setMessageLabelFont:[UIFont systemFontOfSize:14]]; - [[SDCAlertView appearance] setTextFieldFont:[UIFont systemFontOfSize:13]]; - [[SDCAlertView appearance] setSuggestedButtonFont:[UIFont boldSystemFontOfSize:17]]; - [[SDCAlertView appearance] setNormalButtonFont:[UIFont systemFontOfSize:17]]; - [[SDCAlertView appearance] setButtonTextColor:[UIColor colorWithRed:0/255.0 green:122/255.0 blue:255/255.0 alpha:1]]; - [[SDCAlertView appearance] setTextFieldTextColor:[UIColor blackColor]]; - [[SDCAlertView appearance] setTitleLabelTextColor:[UIColor blackColor]]; - [[SDCAlertView appearance] setMessageLabelTextColor:[UIColor blackColor]]; - } - else { - [[SDCAlertView appearance] setTitleLabelFont:[UIFont boldSystemFontOfSize:22]]; - [[SDCAlertView appearance] setMessageLabelFont:[UIFont italicSystemFontOfSize:14]]; - [[SDCAlertView appearance] setNormalButtonFont:[UIFont boldSystemFontOfSize:12]]; - [[SDCAlertView appearance] setSuggestedButtonFont:[UIFont italicSystemFontOfSize:12]]; - [[SDCAlertView appearance] setTextFieldFont:[UIFont italicSystemFontOfSize:12]]; - [[SDCAlertView appearance] setButtonTextColor:[UIColor grayColor]]; - [[SDCAlertView appearance] setTextFieldTextColor:[UIColor purpleColor]]; - [[SDCAlertView appearance] setTitleLabelTextColor:[UIColor greenColor]]; - [[SDCAlertView appearance] setMessageLabelTextColor:[UIColor yellowColor]]; - - } -} - -@end From 76ae9463a97eadbe5ede65606d12cc0ea82b46c0 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 13 Oct 2014 19:54:30 -0700 Subject: [PATCH 67/76] Replace #import <> with @import --- SDCAlertView/Source/SDCAlertView.h | 2 +- SDCAlertView/Source/SDCAlertViewBackgroundView.h | 2 +- SDCAlertView/Source/SDCAlertViewContentView.h | 2 +- SDCAlertView/Source/SDCAlertViewController.h | 2 +- SDCAlertView/Source/SDCIntrinsicallySizedView.h | 2 +- SDCAlertView/Source/UIView+Parallax.h | 2 +- SDCAlertView/Source/UIViewController+Current.h | 3 +++ 7 files changed, 9 insertions(+), 6 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertView.h b/SDCAlertView/Source/SDCAlertView.h index 3704a2ec..bd295339 100644 --- a/SDCAlertView/Source/SDCAlertView.h +++ b/SDCAlertView/Source/SDCAlertView.h @@ -6,7 +6,7 @@ // Copyright (c) 2013 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; FOUNDATION_EXPORT CGFloat const SDCAlertViewWidth; diff --git a/SDCAlertView/Source/SDCAlertViewBackgroundView.h b/SDCAlertView/Source/SDCAlertViewBackgroundView.h index ab8d3218..4265a77d 100644 --- a/SDCAlertView/Source/SDCAlertViewBackgroundView.h +++ b/SDCAlertView/Source/SDCAlertViewBackgroundView.h @@ -6,7 +6,7 @@ // Copyright (c) 2013 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; @interface SDCAlertViewBackgroundView : UIView diff --git a/SDCAlertView/Source/SDCAlertViewContentView.h b/SDCAlertView/Source/SDCAlertViewContentView.h index 371375bf..cc5cbbab 100644 --- a/SDCAlertView/Source/SDCAlertViewContentView.h +++ b/SDCAlertView/Source/SDCAlertViewContentView.h @@ -6,7 +6,7 @@ // Copyright (c) 2013 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; #import "SDCAlertView.h" // Required for SDCAlertViewStyle diff --git a/SDCAlertView/Source/SDCAlertViewController.h b/SDCAlertView/Source/SDCAlertViewController.h index 24293a9e..9980af5b 100644 --- a/SDCAlertView/Source/SDCAlertViewController.h +++ b/SDCAlertView/Source/SDCAlertViewController.h @@ -6,7 +6,7 @@ // Copyright (c) 2013 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; @class SDCAlertView; diff --git a/SDCAlertView/Source/SDCIntrinsicallySizedView.h b/SDCAlertView/Source/SDCIntrinsicallySizedView.h index 3e62ffb1..56863da2 100644 --- a/SDCAlertView/Source/SDCIntrinsicallySizedView.h +++ b/SDCAlertView/Source/SDCIntrinsicallySizedView.h @@ -6,7 +6,7 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; @interface SDCIntrinsicallySizedView : UIView diff --git a/SDCAlertView/Source/UIView+Parallax.h b/SDCAlertView/Source/UIView+Parallax.h index 71c2ce52..c5d306d4 100644 --- a/SDCAlertView/Source/UIView+Parallax.h +++ b/SDCAlertView/Source/UIView+Parallax.h @@ -6,7 +6,7 @@ // Copyright (c) 2014 Scotty Doesn't Code. All rights reserved. // -#import +@import UIKit; @interface UIView (Parallax) diff --git a/SDCAlertView/Source/UIViewController+Current.h b/SDCAlertView/Source/UIViewController+Current.h index e629ebdf..c941ca0d 100644 --- a/SDCAlertView/Source/UIViewController+Current.h +++ b/SDCAlertView/Source/UIViewController+Current.h @@ -10,6 +10,9 @@ @interface UIViewController (Current) +/** + * Returns the currently visible view controller, taking into account navigation controllers and modally presented view controllers. + */ + (UIViewController *)sdc_currentViewController; @end From 5e0ea7739d70f6ef2329f3d310292db9c0095f36 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 13 Oct 2014 20:43:57 -0700 Subject: [PATCH 68/76] Document public API --- SDCAlertView/Source/SDCAlertController.h | 81 +++++++++++++++++++ .../Source/SDCAlertControllerVisualStyle.h | 47 +++++++---- 2 files changed, 114 insertions(+), 14 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index b5618177..6993b78c 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -15,7 +15,9 @@ typedef NS_ENUM(NSInteger, SDCAlertActionStyle) { }; typedef NS_ENUM(NSInteger, SDCAlertControllerStyle) { + /// Default alert. Shows the correct alert based on iOS version. SDCAlertControllerStyleAlert = UIAlertControllerStyleAlert, + /// Use the iOS 7 alert regardless of the current iOS version SDCAlertControllerStyleLegacyAlert }; @@ -50,29 +52,80 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerActionLayout) { - (void)addAction:(SDCAlertAction *)action; @property (nonatomic, readonly) NSArray *actions; + +/** + * Force the actions to lay out either horizontally or vertically. Default is SDCAlertControllerActionLayoutAutomatic, resulting in 2 actions being + * displayed horizontally, and any other number of actions vertically. + */ @property (nonatomic) SDCAlertControllerActionLayout actionLayout; - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler; @property (nonatomic, readonly) NSArray *textFields; @property (nonatomic, copy) NSString *title; + +/** + * The attributed title for the alert. Both \c title and \c attributedTitle can be used to set the title of the alert, + * the title will be set to whichever was called last. That means that setting \c title to \c nil after setting the + * \c attributedTitle will result in no title showing. + */ @property (nonatomic, copy) NSAttributedString *attributedTitle; @property (nonatomic, copy) NSString *message; + +/** + * The attributed message for the alert. Both \c message and \c attributedMessage can be used to set the message of the + * alert, but the message will be set to whichever was called last. That means that setting \c mesage to \c nil after + * setting the \c attributedMessage will result in no message showing. + */ @property (nonatomic, copy) NSAttributedString *attributedMessage; +/** + * The contentView property can be used to display any arbitrary view in an alert view by adding these views to the contentView. + * SDCAlertView uses auto-layout to layout all its subviews, including the contentView. That means that you should not + * modify the contentView's frame property, as it will do nothing. Use NSLayoutConstraint or helper methods included in + * SDCAutoLayout to modify the contentView's dimensions. + * + * The contentView will take up the entire width of the alert. The height cannot be automatically determined and will + * need to be explicitly defined. + * + * If there are no subviews, the contentView will not be added to the alert. + */ @property (nonatomic, readonly) UIView *contentView; @property (nonatomic, readonly) SDCAlertControllerStyle preferredStyle; + + +/** + * The alert's visual style defines how the different alert elements will look. Any class that implements this protocol and returns valid values can + * be assigned to this property. This deprecates UIAppearance support in SDCAlertView 1.0, as all old UIAppearance-enabled properties are part of the + * visual style. + */ @property (nonatomic, strong) id visualStyle; +/** + * A block that determines whether an action should dismiss the alert or not. The \c action parameter is the action that originally called this block. + */ @property (nonatomic, copy) BOOL (^shouldDismissBlock)(SDCAlertAction *action); @end @interface SDCAlertController (Presentation) +/** + * Instead of calling \c presentViewController:animated:completion: on some view controller, you can use this method and the alert will figure out + * what view controller to present itself from. This enables you to show alerts directly from, for example, network layers that don't necessarily know + * about any view controllers but need to present an error or info message. + * + * This method is what brings backwards compatibility to SDCAlertView. It will smartly show a 1.0 (iOS 7) or 2.0 (iOS 8) alert based on the iOS version + * of the user. + */ - (void)presentWithCompletion:(void(^)(void))completion; + +/** + * This method can be used as any easy way to dismiss an alert without having to know exactly which view controller it was presented from. This brings + * backwards compatibility to SDCAlertView, and will cause a call to \c dismissWithClickedButtonIndex:animated: on an iOS 7 alert. + */ - (void)dismissWithCompletion:(void(^)(void))completion; @end @@ -80,7 +133,35 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerActionLayout) { @class SDCAlertView; @interface SDCAlertController (Legacy) +/* + * SDCAlertController is backwards compatible with SDCAlertView. This means that you can simply create an SDCAlertController instance and use that to + * display an alert on both iOS 7 and iOS 8. Most, if not all, functionality that is present in SDCAlertView has been ported back from + * SDCAlertController. + * + * In a case where some functionality is not ported back, you'll be able to make the customization yourself by using the \c legacyAlertView property, + * which will return the SDCAlertView instance that is presented. For example, this could be an initialization pattern for an alert that needs to be + * shown on iOS 7 and iOS 8: + * + * SDCAlertController *alert = [SDCAlertController alertWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; + * // ... configure alert with content view, text fields, buttons, etc ... + * + * if (alert.usesLegacyAlert) { + * // ... use alert.legacyAlertView to make iOS 7 modifications + * } else { + * // Keep using original alert + * } + * + * [alert presentWithCompletion:nil]; + */ + +/** + * After creating an alert controller, use this property to determine whether or not a legacy (1.0/iOS 7) alert will be used. + */ @property (nonatomic, readonly) BOOL usesLegacyAlert; + +/** + * If the alert controller will use a legacy alert, this will return the instance of that legacy alert. Otherwise, it will return \c nil. + */ @property (nonatomic, readonly) SDCAlertView *legacyAlertView; @end diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index 169c875c..c341942d 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -12,32 +12,51 @@ @protocol SDCAlertControllerVisualStyle -@property (nonatomic, readonly) CGFloat cornerRadius; -@property (nonatomic, readonly) UIOffset parallax; +/* + * Alert-related values + */ @property (nonatomic, readonly) CGFloat width; -@property (nonatomic, readonly) CGFloat actionViewHeight; -@property (nonatomic, readonly) CGFloat minimumActionViewWidth; // For forced horizontal layout and 3+ buttons +@property (nonatomic, readonly) CGFloat cornerRadius; +@property (nonatomic, readonly) UIEdgeInsets contentPadding; +/// The margins determine the distance between the edge of the screen and the alert @property (nonatomic, readonly) UIEdgeInsets margins; -@property (nonatomic, readonly) UIEdgeInsets contentPadding; -@property (nonatomic, readonly) CGFloat labelSpacing; -@property (nonatomic, readonly) CGFloat estimatedTextFieldHeight; -@property (nonatomic, readonly) CGFloat textFieldsTopSpacing; -@property (nonatomic, readonly) CGFloat textFieldBorderWidth; -@property (nonatomic, readonly) UIColor *textFieldBorderColor; -@property (nonatomic, readonly) UIEdgeInsets textFieldMargins; +/// The alert's parallax magnitude in horizontal and vertical directions. +@property (nonatomic, readonly) UIOffset parallax; -@property (nonatomic, readonly) UIView *actionViewHighlightBackgroundView; -@property (nonatomic, readonly) UIColor *actionViewSeparatorColor; -@property (nonatomic, readonly) CGFloat actionViewSeparatorThickness; +/* + * Title and message label values + */ @property (nonatomic, readonly) UIFont *titleLabelFont; @property (nonatomic, readonly) UIFont *messageLabelFont; @property (nonatomic, readonly) UIFont *textFieldFont; +@property (nonatomic, readonly) CGFloat labelSpacing; + +/* + * Action-related values + */ + +@property (nonatomic, readonly) CGFloat actionViewHeight; +@property (nonatomic, readonly) CGFloat minimumActionViewWidth; // For forced horizontal layout and 3+ buttons +@property (nonatomic, readonly) UIView *actionViewHighlightBackgroundView; +@property (nonatomic, readonly) UIColor *actionViewSeparatorColor; +@property (nonatomic, readonly) CGFloat actionViewSeparatorThickness; + - (UIColor *)textColorForAction:(SDCAlertAction *)action; - (UIFont *)fontForAction:(SDCAlertAction *)action; +/* + * Text field-related values + */ + +@property (nonatomic, readonly) CGFloat estimatedTextFieldHeight; +@property (nonatomic, readonly) CGFloat textFieldsTopSpacing; +@property (nonatomic, readonly) CGFloat textFieldBorderWidth; +@property (nonatomic, readonly) UIColor *textFieldBorderColor; +@property (nonatomic, readonly) UIEdgeInsets textFieldMargins; + @end From c59d65fd9703dc0215a6bf11fdfa18fe148dc93d Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Mon, 13 Oct 2014 20:46:33 -0700 Subject: [PATCH 69/76] Remove redundant property --- SDCAlertView/Source/SDCAlertController.h | 7 +------ SDCAlertView/Source/SDCAlertController.m | 4 ++-- SDCAlertView/Source/SDCDemoViewController.m | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index 6993b78c..e69ed994 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -155,12 +155,7 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerActionLayout) { */ /** - * After creating an alert controller, use this property to determine whether or not a legacy (1.0/iOS 7) alert will be used. - */ -@property (nonatomic, readonly) BOOL usesLegacyAlert; - -/** - * If the alert controller will use a legacy alert, this will return the instance of that legacy alert. Otherwise, it will return \c nil. + * Returns the SDCAlertView instance that will be presented IF it will be presented (based on preferred alert style or iOS version), otherwise \c nil. */ @property (nonatomic, readonly) SDCAlertView *legacyAlertView; @end diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index 676858aa..da1fa7b4 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -100,7 +100,7 @@ - (void)dealloc { #pragma mark - Alert View - (SDCAlertView *)legacyAlertView { - if (!_legacyAlertView && self.usesLegacyAlert) { + if (!_legacyAlertView && [self usesLegacyAlert]) { _legacyAlertView = [SDCAlertView alertViewWithAlertController:self]; } return _legacyAlertView; @@ -136,7 +136,7 @@ - (void)createAlert { - (void)showTextFieldsInAlertView:(SDCAlertControllerView *)alertView { if (self.textFields.count > 0) { SDCAlertControllerTextFieldViewController *textFieldViewController = [[SDCAlertControllerTextFieldViewController alloc] initWithTextFields:self.textFields - visualStyle:self.visualStyle]; + visualStyle:self.visualStyle]; [self addChildViewController:textFieldViewController]; [alertView showTextFieldViewController:textFieldViewController]; [textFieldViewController didMoveToParentViewController:self]; diff --git a/SDCAlertView/Source/SDCDemoViewController.m b/SDCAlertView/Source/SDCDemoViewController.m index a904cfc9..bd6694c1 100644 --- a/SDCAlertView/Source/SDCDemoViewController.m +++ b/SDCAlertView/Source/SDCDemoViewController.m @@ -62,7 +62,7 @@ - (void)showAlertWithStyle:(SDCAlertControllerStyle)style { alert.actionLayout = self.buttonLayoutControl.selectedSegmentIndex; - if (self.selectedContentViewIndex > 0 && alert.usesLegacyAlert) { + if (self.selectedContentViewIndex > 0 && alert.legacyAlertView) { [self addContentToView:alert.legacyAlertView.contentView]; [alert presentWithCompletion:nil]; } else if (self.selectedContentViewIndex > 0) { From f0bc0bbe33f5d9622d4e218762b61143196f5e4a Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Tue, 14 Oct 2014 21:57:28 -0700 Subject: [PATCH 70/76] Update documentation --- SDCAlertView/Source/SDCAlertController.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDCAlertView/Source/SDCAlertController.h b/SDCAlertView/Source/SDCAlertController.h index e69ed994..7f618299 100644 --- a/SDCAlertView/Source/SDCAlertController.h +++ b/SDCAlertView/Source/SDCAlertController.h @@ -145,7 +145,7 @@ typedef NS_ENUM(NSInteger, SDCAlertControllerActionLayout) { * SDCAlertController *alert = [SDCAlertController alertWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; * // ... configure alert with content view, text fields, buttons, etc ... * - * if (alert.usesLegacyAlert) { + * if (alert.legacyAlertView) { * // ... use alert.legacyAlertView to make iOS 7 modifications * } else { * // Keep using original alert From a4d5f8e4408c626b37117bbf6af8ea652f8f4960 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Tue, 14 Oct 2014 22:29:34 -0700 Subject: [PATCH 71/76] Correctly apply tintColor --- SDCAlertView/Source/SDCAlertCollectionViewCell.m | 4 ++++ SDCAlertView/Source/SDCAlertController.m | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index 9bde347b..c5f19bdb 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -47,6 +47,10 @@ - (void)setEnabled:(BOOL)enabled { self.gestureRecognizer.enabled = enabled; } +- (void)tintColorDidChange { + self.textLabel.textColor = self.tintColor; +} + - (void)updateWithAction:(SDCAlertAction *)action visualStyle:(id)visualStyle { if (action.attributedTitle) { self.textLabel.attributedText = action.attributedTitle; diff --git a/SDCAlertView/Source/SDCAlertController.m b/SDCAlertView/Source/SDCAlertController.m index da1fa7b4..cc121459 100644 --- a/SDCAlertView/Source/SDCAlertController.m +++ b/SDCAlertView/Source/SDCAlertController.m @@ -149,8 +149,8 @@ - (UIView *)contentView { #pragma mark - Lifecycle -- (void)viewDidLoad { - [super viewDidLoad]; +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardUpdate:) name:UIKeyboardWillChangeFrameNotification object:nil]; From 6e61b5ea95cf71e0d2b176431632d130fc71f8f8 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Tue, 14 Oct 2014 23:06:08 -0700 Subject: [PATCH 72/76] Correctly pad message label --- .../Source/SDCAlertControllerDefaultVisualStyle.m | 2 +- SDCAlertView/Source/SDCAlertControllerScrollView.m | 10 +++++++--- SDCAlertView/Source/SDCAlertControllerVisualStyle.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index 24fc5232..3fc280ba 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -48,7 +48,7 @@ - (CGFloat)estimatedTextFieldHeight { return 25; } -- (CGFloat)textFieldsTopSpacing { +- (CGFloat)messageLabelBottomSpacing { return 24; } diff --git a/SDCAlertView/Source/SDCAlertControllerScrollView.m b/SDCAlertView/Source/SDCAlertControllerScrollView.m index f1445da2..0a0077b3 100644 --- a/SDCAlertView/Source/SDCAlertControllerScrollView.m +++ b/SDCAlertView/Source/SDCAlertControllerScrollView.m @@ -106,7 +106,7 @@ - (void)layoutSubviews { toItem:self.messageLabel attribute:NSLayoutAttributeLastBaseline multiplier:1 - constant:self.visualStyle.textFieldsTopSpacing]]; + constant:self.visualStyle.messageLabelBottomSpacing]]; } [self invalidateIntrinsicContentSize]; @@ -118,8 +118,12 @@ - (void)invalidateIntrinsicContentSize { } - (CGSize)intrinsicContentSize { - UIView *lastView = (self.textFieldViewController) ? self.textFieldViewController.view : self.messageLabel; - CGFloat intrinsicHeight = CGRectGetMaxY(lastView.frame); + CGFloat intrinsicHeight = 0; + if (self.textFieldViewController) { + intrinsicHeight = CGRectGetMaxY(self.textFieldViewController.view.frame); + } else { + intrinsicHeight = CGRectGetMaxY(self.messageLabel.frame) + self.visualStyle.messageLabelBottomSpacing; // Not perfect, as padding it added from the bottom of the label, not its baseline + } return CGSizeMake(UIViewNoIntrinsicMetric, intrinsicHeight); } diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index c341942d..fb393dae 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -35,6 +35,7 @@ @property (nonatomic, readonly) UIFont *textFieldFont; @property (nonatomic, readonly) CGFloat labelSpacing; +@property (nonatomic, readonly) CGFloat messageLabelBottomSpacing; /* * Action-related values @@ -54,7 +55,6 @@ */ @property (nonatomic, readonly) CGFloat estimatedTextFieldHeight; -@property (nonatomic, readonly) CGFloat textFieldsTopSpacing; @property (nonatomic, readonly) CGFloat textFieldBorderWidth; @property (nonatomic, readonly) UIColor *textFieldBorderColor; @property (nonatomic, readonly) UIEdgeInsets textFieldMargins; From db9cb1420b96172fe7d4743edb3ec8116e867c91 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 15 Oct 2014 19:44:23 -0700 Subject: [PATCH 73/76] Organize methods in classes --- README.md | 154 ++++++++---------- .../Source/SDCAlertCollectionViewCell.m | 18 +- ...CAlertControllerCollectionViewFlowLayout.m | 5 +- .../SDCAlertControllerDefaultVisualStyle.m | 81 +++++---- .../Source/SDCAlertControllerScrollView.m | 2 + SDCAlertView/Source/SDCAlertControllerView.m | 76 +++++---- .../Source/SDCAlertControllerVisualStyle.h | 18 +- 7 files changed, 177 insertions(+), 177 deletions(-) diff --git a/README.md b/README.md index 7e98d7b5..d47679b3 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,53 @@ -#SDCAlertView +# SDCAlertView `SDCAlertView` doesn't just look like a system alert in terms of user interface elements, it is the result of completely reverse-engineering `UIAlertView`. View hierarchy, labels, buttons, animations, user interaction; everything has been looked at and incorporated as much as possible. You can think of `SDCAlertView` as `UIAlertView` on steroids. It has added functionality such as a `contentView` property and block syntax, while still keeping the `UIAlertView` look. -![Animated GIF showing alert](http://sberrevoets.github.io/SDCAlertView/ProgressViewAlert.gif) +## iOS 8 & `UIAlertController` +In iOS 8, `UIAlertView` was deprecated in favor of `UIAlertController`. `SDCAlertView` was also updated to include `SDCAlertController`, whose API matches its `UI` counterpart. + +But that wasn't all, the entire view hierarchy changed again and even the way of presenting the alert changed. Fortunately, the new implementation was a lot easier to copy, though some sacrifices had to be made in terms of likeness. The culprits, two private classes by the name of `_UIBackdropView` and `_UIBlendingHighlightView`, were used quite a bit, and although `UIVisualEffectView` comes close to making it look exactly right, there are differences. + +Ignoring minor differences (that you would really only see if you looked for them), everything that was possible in `SDCAlertView` is also possible in `SDCAlertController`, though probably in the form of a new API. `SDCAlertController` is backwards compatible with `SDCAlertView`, meaning you can replace your existing `SDCAlertView` instances with `SDCAlertController` instances, even if your deployment target is iOS 7. + +**This means that you should rarely use `SDCAlertView` anymore. Consider it, just like `UIAlertView`, deprecated and only use `SDCAlertController` moving forward. If you want to keep using `SDCAlertView` because it has functionality `SDCAlertController` does not, open an issue. This is considered a bug.** ## Installation The easiest way to install is, of course, by using CocoaPods. The name of the pod is `SDCAlertView`. -If you're not using CocoaPods, you need: +If you're not using CocoaPods, you need all classes in the [Source](https://github.com/sberrevoets/SDCAlertView/tree/master/SDCAlertView/Source) directory. -- SDCAlertView.{h,m} -- SDCAlertViewTransitioning.h -- SDCAlertViewCoordinator.{h,m} -- SDCAlertViewController.{h,m} -- SDCAlertViewContentView.{h,m} -- SDCAlertViewBackgroundView.{h,m} -- SDCIntrinsicallySizedView.{h,m} - -The project also depends on [RBBAnimation](https://github.com/robb/RBBAnimation) and [SDCAutoLayout](https://github.com/Scott90/SDCAutoLayout). These dependencies are automatically handled for you if you use CocoaPods. +The project also depends on [RBBAnimation](https://github.com/robb/RBBAnimation) (`SDCAlertView` only) and [SDCAutoLayout](https://github.com/sberrevoets/SDCAutoLayout). These dependencies are automatically handled for you if you use CocoaPods. ## Usage -`SDCAlertView` is for use in iOS 7 only. It will not work properly on iOS 6.1 or below. Using `SDCAlertView` is very simple: just import SDCAlertView.h and use it as you would `UIAlertView`. +`SDCAlertController` is for use in iOS 7 or higher only. It will not work properly on iOS 6.1 or below. Using the library is very simple: just import SDCAlertController.h and use it as you would `UIAlertController`. ### Basic -Showing a basic `SDCAlertView` alert looks just like showing a basic `UIAlertView` alert: +Showing a basic `SDCAlertController` alert looks just like showing a basic `UIAlertController` alert: ```objc -SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Title" - message:@"This is a message" - delegate:self - cancelButtonTitle:@"Cancel" - otherButtonTitles:@"OK", nil]; -[alert show]; +SDCAlertController *alert = [SDCAlertController alertControllerWithTitle:@"Title" + message:@"This is a message" + preferredStyle:SDCAlertControllerStyleAlert]; +[alert addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:nil]]; +[alert presentWithCompletion:nil]; ``` Or you can use one of the convenience methods: ```objc -[SDCAlertView alertWithTitle:@"Title" message:@"This is a message" buttons:@[@"OK"]]; -``` - -### Block syntax - -Block syntax saves you from having to use a delegate: -```objc -SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Title" - message:@"This is a message" - delegate:nil - cancelButtonTitle:@"Cancel" - otherButtonTitles:@"OK", nil]; -[alert showWithDismissHandler:^(NSInteger buttonIndex) { - NSLog(@"Tapped button: %@", @(buttonIndex)); -}]; +[SDCAlertController showAlertControllerWithTitle:@"Title" message:@"This is a message" actionTitle:@"OK"] ``` ### `contentView` Of course, you're not using `SDCAlertView`'s full potential unless you are using the `contentView`: ```objc -SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:@"Title" - message:@"This is a message" - delegate:self - cancelButtonTitle:@"Cancel" - otherButtonTitles:@"OK", nil]; - +SDCAlertController *alert = [SDCAlertController alertControllerWithTitle:@"Title" + message:@"This is a message" + preferredStyle:SDCAlertControllerStyleAlert]; +[alert addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:nil]]; + UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] init]; spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; [spinner setTranslatesAutoresizingMaskIntoConstraints:NO]; @@ -72,67 +55,69 @@ spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; [alert.contentView addSubview:spinner]; [spinner sdc_horizontallyCenterInSuperview]; -[spinner sdc_verticallyCenterInSuperviewWithOffset:SDCAutoLayoutStandardSiblingDistance]; -[alert show]; +[alert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[spinner]-|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(spinner)]]; + +[alert presentWithCompletion:nil]; ``` -### Additional delegate methods +### Dismissal Prevention + +You can use the `shouldDismissBlock` to prevent an alert from being dismissed: -You can also use the `alertView:shouldDismissWithButtonIndex:` and `alertView:shouldDeselectButtonAtIndex:` to prevent an alert from dismissing: ```objc -- (void)showAlert { - SDCAlertView *alert = [[SDCAlertView alloc] initWithTitle:title - message:message - delegate:self - cancelButtonTitle:@"Cancel" - otherButtonTitles:nil]; - [alert show]; -} +SDCAlertController *alert = [SDCAlertController alertControllerWithTitle:@"Title" + message:@"This is a message" + preferredStyle:SDCAlertControllerStyleAlert]; +[alert addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:nil]]; -- (BOOL)alertView:(SDCAlertView *)alertView shouldDismissWithButtonIndex:(NSInteger)buttonIndex { +alert.shouldDismissBlock = ^ BOOL(SDCAlertAction *action) { return NO; -} +}; -- (BOOL)alertView:(SDCAlertView *)alertView shouldDeselectButtonAtIndex:(NSInteger)buttonIndex { - return YES; -} +[alert presentWithCompletion:nil]; ``` -This will deselect the cancel button when it's tapped, but it won't actually dismiss the alert. Useful for password-like alerts that you don't want dismissed until the right password is entered. -### Styling and appearance +### Styling and Appearance + +`SDCAlertController` is a normal view controller, so applying a `tintColor` to its `view` will color the buttons and any subviews you add to the `contentView`. If you are looking for more customizations, create a class that conforms to the `SDCAlertControllerVisualStyle` protocol and set it as the `visualStyle` on an `SDCAlertController` instance. You can also subclass `SDCAlertControllerDefaultVisualStyle` for a set of default values that you can then override as needed. + +If you're feeling particularly adventurous, you can use a different transition/animation by creating a class that conforms to `UIViewControllerTransitioningDelegate` and setting it as the alert's `transitionCoordinator`. Transitioning is implemented using default iOS 8 custom view controller transitions, so anything you can do with a normal view controller, you can do with an alert controller. + +## Backwards compatibility + +`SDCAlertController` will in most cases be backwards compatible with `SDCAlertView`. However, most is not all, and if you need to fine-tune an alert just for iOS 7, you can still do that: -`SDCAlertView` uses the `tintColor` for buttons and any subviews you add to the `contentView`. If you are looking for more customizations, you can use `UIAppearance` to style alerts (per instance or all at once): ```objc -[[SDCAlertView appearance] setTitleLabelFont:[UIFont boldSystemFontOfSize:22]]; -[[SDCAlertView appearance] setMessageLabelFont:[UIFont italicSystemFontOfSize:14]]; -[[SDCAlertView appearance] setNormalButtonFont:[UIFont boldSystemFontOfSize:12]]; -[[SDCAlertView appearance] setSuggestedButtonFont:[UIFont italicSystemFontOfSize:12]]; -[[SDCAlertView appearance] setTextFieldFont:[UIFont italicSystemFontOfSize:12]]; -[[SDCAlertView appearance] setButtonTextColor:[UIColor grayColor]]; // will always override the tintColor -[[SDCAlertView appearance] setTextFieldTextColor:[UIColor purpleColor]]; -[[SDCAlertView appearance] setTitleLabelTextColor:[UIColor greenColor]]; -[[SDCAlertView appearance] setMessageLabelTextColor:[UIColor yellowColor]]; +SDCAlertController *alert = [SDCAlertController alertWithTitle:@"Title" message:@"Message" preferredStyle:SDCAlertControllerStyleAlert]; +// ... configure alert with content view, text fields, buttons, etc ... + +if (alert.legacyAlertView) { + // ... use alert.legacyAlertView to make iOS 7 modifications +} else { + // Keep using original alert +} + +[alert presentWithCompletion:nil]; ``` -If you're feeling particularly adventurous, `SDCAlertView` makes it very easy to customize the way alerts are presented and dismissed. Set the `transitionCoordinator` property to a custom class that conforms to `SDCAlertViewTransitioning`, and implement the three protocol methods. For more detailed instructions, see SDCAlertViewTransitioning.h. +## Behavior different from `UIAlertController` -## Behavior different from `UIAlertView` -Unfortunately, there are a few things that can't or won't be duplicated: +With the introduction of `SDCAlertController`, pretty much all behavior in alerts could be replicated. If you use the legacy `SDCAlertView`, you may run into some additional problems as described below: -- Special interaction with the system. The system does not consider instances of `SDCAlertView` actual alerts, which means that, for example, the `alertViewCancel:` method from `SDCAlertViewDelegate` will never be called. -- `UITextField` placeholders in different languages. "Login" and "Password" are entered as localized strings, but they aren't actually translated. -- Some behavior is purposely not ported from `UIAlertView`. These cases are discussed in SDCAlertView.h. +- Special interaction with the system. The system does not consider instances of `SDCAlertController` actual alerts, which means that won't experience the normal system interaction you'd expect from a normal alert. This also means that combining `SDCAlertView` with `SDCAlertController` is a **bad idea**. +- **`SDCAlertView` only:** `UITextField` placeholders in different languages. "Login" and "Password" are entered as localized strings, but they aren't actually translated. +- **`SDCAlertView` only:** Some behavior is purposely not ported from `UIAlertView`. These cases are discussed in SDCAlertView.h. -## New in 1.4 +## New in 2.0 **What's New:** - - Added the ability to position a two-button alert vertically as opposed to horizontally - - Added `attributedTitle` and `attributedMessage` properties - -**Bug Fixes:** - - Auto-layout doesn't complain anymore when using `[[SDCAlertView alloc] init]` - - Fixes a bug that would not show correct button titles in certain alert configurations - - Instead of clipping button text, it now reduces the size of text on buttons appropriately + - All new API that matches and extends `UIAlertController` + - Ability to always show buttons horizontally or vertically + - Backwards compatible with `SDCAlertView` (1.0) + - More stylistic elements you can style (alert width, button separators, text fields, etc.) ## Support I'm pretty active on [Stack Overflow](http://stackoverflow.com/users/751268/scott-berrevoets), so please use that if you have any questions. You can also use [Twitter](http://twitter.com/ScottBerrevoets) to contact me directly. @@ -144,6 +129,5 @@ Some credits are in order: - Robert Böhnke ([@robb](https://github.com/robb)): [RBBAnimation](https://github.com/robb/RBBAnimation) - Lee McDermott ([@lmcd](https://github.com/lmcd)) for reverse-engineering the showing and dismissing animations. -- César Castillo ([@JagCesar](https://github.com/JagCesar)) for the great idea of using a `UIToolbar` for easy live blurring (used in earlier versions of SDCAlertView). And everyone else who contributed by reporting issues, creating pull requests, or in some other way! \ No newline at end of file diff --git a/SDCAlertView/Source/SDCAlertCollectionViewCell.m b/SDCAlertView/Source/SDCAlertCollectionViewCell.m index c5f19bdb..365d33c7 100644 --- a/SDCAlertView/Source/SDCAlertCollectionViewCell.m +++ b/SDCAlertView/Source/SDCAlertCollectionViewCell.m @@ -47,6 +47,16 @@ - (void)setEnabled:(BOOL)enabled { self.gestureRecognizer.enabled = enabled; } +- (void)setHighlighted:(BOOL)highlighted { + [super setHighlighted:highlighted]; + + if (self.isEnabled) { + self.highlightedBackgroundView.hidden = !highlighted; + } +} + +#pragma mark - User Interface + - (void)tintColorDidChange { self.textLabel.textColor = self.tintColor; } @@ -78,14 +88,6 @@ - (void)layoutSubviews { [self.textLabel sdc_centerInSuperview]; } -- (void)setHighlighted:(BOOL)highlighted { - [super setHighlighted:highlighted]; - - if (self.isEnabled) { - self.highlightedBackgroundView.hidden = !highlighted; - } -} - @end @implementation SDCAlertControllerSeparatorView diff --git a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m index b5bf396e..0c97f604 100644 --- a/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m +++ b/SDCAlertView/Source/SDCAlertControllerCollectionViewFlowLayout.m @@ -49,8 +49,9 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { } - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { - SDCAlertControllerCollectionViewLayoutAttributes *attributes = [SDCAlertControllerCollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:elementKind - withIndexPath:indexPath]; + SDCAlertControllerCollectionViewLayoutAttributes *attributes = [SDCAlertControllerCollectionViewLayoutAttributes + layoutAttributesForDecorationViewOfKind:elementKind + withIndexPath:indexPath]; UICollectionViewLayoutAttributes *itemAttributes = [self layoutAttributesForItemAtIndexPath:indexPath]; attributes.zIndex = itemAttributes.zIndex + 1; diff --git a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m index 3fc280ba..77a95710 100644 --- a/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m +++ b/SDCAlertView/Source/SDCAlertControllerDefaultVisualStyle.m @@ -12,58 +12,57 @@ @implementation SDCAlertControllerDefaultVisualStyle -- (CGFloat)cornerRadius { - return 7; -} - -- (UIOffset)parallax { - return UIOffsetMake(15.75, 15.75); -} +#pragma mark - Alert - (CGFloat)width { return 270; } -- (CGFloat)actionViewHeight { - return 44; +- (UIEdgeInsets)contentPadding { + return UIEdgeInsetsMake(36, 16, 12, 16); } -- (CGFloat)minimumActionViewWidth { - return 90; // Fits exactly three actions without scrolling +- (CGFloat)cornerRadius { + return 7; } - (UIEdgeInsets)margins { return UIEdgeInsetsMake(3, 0, 3, 0); } -- (UIEdgeInsets)contentPadding { - return UIEdgeInsetsMake(36, 16, 12, 16); +- (UIOffset)parallax { + return UIOffsetMake(15.75, 15.75); } -- (CGFloat)labelSpacing { - return 18; +#pragma mark - Title & Message Labels + +- (UIFont *)titleLabelFont { + return [UIFont boldSystemFontOfSize:17]; } -- (CGFloat)estimatedTextFieldHeight { - return 25; +- (UIFont *)messageLabelFont { + return [UIFont systemFontOfSize:13]; +} + +- (CGFloat)labelSpacing { + return 18; } - (CGFloat)messageLabelBottomSpacing { return 24; } -- (CGFloat)textFieldBorderWidth { - return 1 / [UIScreen mainScreen].scale; -} +#pragma mark - Actions -- (UIColor *)textFieldBorderColor { - return [UIColor colorWithRed:64.f/255 green:64.f/255 blue:64.f/255 alpha:1]; +- (CGFloat)actionViewHeight { + return 44; } -- (UIEdgeInsets)textFieldMargins { - return UIEdgeInsetsMake(4, 4, 4, 4); +- (CGFloat)minimumActionViewWidth { + return 90; // Fits exactly three actions without scrolling } + - (UIView *)actionViewHighlightBackgroundView { UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor colorWithWhite:.80 alpha:.7]; @@ -78,18 +77,6 @@ - (CGFloat)actionViewSeparatorThickness { return 1 / [UIScreen mainScreen].scale; } -- (UIFont *)titleLabelFont { - return [UIFont boldSystemFontOfSize:17]; -} - -- (UIFont *)messageLabelFont { - return [UIFont systemFontOfSize:13]; -} - -- (UIFont *)textFieldFont { - return [UIFont systemFontOfSize:13]; -} - - (UIColor *)textColorForAction:(SDCAlertAction *)action { if (action.style == SDCAlertActionStyleDestructive) { return [UIColor redColor]; @@ -106,4 +93,26 @@ - (UIFont *)fontForAction:(SDCAlertAction *)action { } } +#pragma mark - Text Fields + +- (UIFont *)textFieldFont { + return [UIFont systemFontOfSize:13]; +} + +- (CGFloat)estimatedTextFieldHeight { + return 25; +} + +- (CGFloat)textFieldBorderWidth { + return 1 / [UIScreen mainScreen].scale; +} + +- (UIColor *)textFieldBorderColor { + return [UIColor colorWithRed:64.f/255 green:64.f/255 blue:64.f/255 alpha:1]; +} + +- (UIEdgeInsets)textFieldMargins { + return UIEdgeInsetsMake(4, 4, 4, 4); +} + @end diff --git a/SDCAlertView/Source/SDCAlertControllerScrollView.m b/SDCAlertView/Source/SDCAlertControllerScrollView.m index 0a0077b3..e798a266 100644 --- a/SDCAlertView/Source/SDCAlertControllerScrollView.m +++ b/SDCAlertView/Source/SDCAlertControllerScrollView.m @@ -70,6 +70,8 @@ - (void)setTextFieldViewController:(SDCAlertControllerTextFieldViewController *) [self addSubview:textFieldViewController.view]; } +#pragma mark - Layout + - (void)layoutSubviews { [super layoutSubviews]; diff --git a/SDCAlertView/Source/SDCAlertControllerView.m b/SDCAlertView/Source/SDCAlertControllerView.m index c06d2f75..8b7d3dd8 100644 --- a/SDCAlertView/Source/SDCAlertControllerView.m +++ b/SDCAlertView/Source/SDCAlertControllerView.m @@ -30,6 +30,8 @@ @interface SDCAlertControllerView () )visualStyle { [self sdc_addParallax:visualStyle.parallax]; } +#pragma mark - Content + - (void)showTextFieldViewController:(SDCAlertControllerTextFieldViewController *)viewController { self.scrollView.textFieldViewController = viewController; } +- (void)actionViewTapped:(UITapGestureRecognizer *)sender { + SDCAlertCollectionViewCell *cell = (SDCAlertCollectionViewCell *)sender.view; + NSIndexPath *indexPath = [self.actionsCollectionView indexPathForCell:cell]; + SDCAlertAction *action = self.actions[indexPath.row]; + + [self.delegate alertControllerView:self didPerformAction:action]; +} + +#pragma mark - User Interface + - (CGFloat)maximumHeightForScrollView { CGFloat maximumHeight = CGRectGetHeight(self.superview.bounds) - self.visualStyle.margins.top - self.visualStyle.margins.bottom; @@ -112,17 +134,6 @@ - (CGFloat)maximumHeightForScrollView { return maximumHeight; } -- (CGFloat)collectionViewHeight { - CGFloat horizontalLayoutHeight = self.visualStyle.actionViewHeight; - CGFloat verticalLayoutHeight = self.visualStyle.actionViewHeight * [self.actionsCollectionView numberOfItemsInSection:0]; - - switch (self.actionLayout) { - case SDCAlertControllerActionLayoutAutomatic: return (self.actions.count == 2) ? horizontalLayoutHeight : verticalLayoutHeight; - case SDCAlertControllerActionLayoutHorizontal: return horizontalLayoutHeight; - case SDCAlertControllerActionLayoutVertical: return verticalLayoutHeight; - } -} - - (void)prepareForDisplay { [self observeActions]; [self applyCurrentStyleToAlertElements]; @@ -155,6 +166,18 @@ - (void)prepareForDisplay { [self.visualEffectView sdc_alignEdgesWithSuperview:UIRectEdgeAll]; } +- (void)layoutSubviews { + [super layoutSubviews]; + self.maximumHeightConstraint.constant = [self maximumHeightForScrollView]; +} + +- (void)applyCurrentStyleToAlertElements { + self.scrollView.visualStyle = self.visualStyle; + self.collectionViewLayout.visualStyle = self.visualStyle; +} + +#pragma mark - KVO + - (void)observeActions { [self.actions enumerateObjectsUsingBlock:^(SDCAlertAction *action, NSUInteger idx, BOOL *stop) { [action addObserver:self forKeyPath:@"enabled" options:0 context:NULL]; @@ -171,32 +194,19 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N } } -- (void)dealloc { - [self.actions enumerateObjectsUsingBlock:^(SDCAlertAction *action, NSUInteger idx, BOOL *stop) { - [action removeObserver:self forKeyPath:@"enabled"]; - }]; -} - -- (void)layoutSubviews { - [super layoutSubviews]; - self.maximumHeightConstraint.constant = [self maximumHeightForScrollView]; -} - -- (void)applyCurrentStyleToAlertElements { - self.scrollView.visualStyle = self.visualStyle; - self.collectionViewLayout.visualStyle = self.visualStyle; -} +#pragma mark - UICollectionView -- (void)actionViewTapped:(UITapGestureRecognizer *)sender { - SDCAlertCollectionViewCell *cell = (SDCAlertCollectionViewCell *)sender.view; - NSIndexPath *indexPath = [self.actionsCollectionView indexPathForCell:cell]; - SDCAlertAction *action = self.actions[indexPath.row]; +- (CGFloat)collectionViewHeight { + CGFloat horizontalLayoutHeight = self.visualStyle.actionViewHeight; + CGFloat verticalLayoutHeight = self.visualStyle.actionViewHeight * [self.actionsCollectionView numberOfItemsInSection:0]; - [self.delegate alertControllerView:self didPerformAction:action]; + switch (self.actionLayout) { + case SDCAlertControllerActionLayoutAutomatic: return (self.actions.count == 2) ? horizontalLayoutHeight : verticalLayoutHeight; + case SDCAlertControllerActionLayoutHorizontal: return horizontalLayoutHeight; + case SDCAlertControllerActionLayoutVertical: return verticalLayoutHeight; + } } -#pragma mark - UICollectionViewDelegate - - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.actions.count; } diff --git a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h index fb393dae..51c7d6d1 100644 --- a/SDCAlertView/Source/SDCAlertControllerVisualStyle.h +++ b/SDCAlertView/Source/SDCAlertControllerVisualStyle.h @@ -12,9 +12,7 @@ @protocol SDCAlertControllerVisualStyle -/* - * Alert-related values - */ +#pragma mark - Alert @property (nonatomic, readonly) CGFloat width; @property (nonatomic, readonly) CGFloat cornerRadius; @@ -26,20 +24,15 @@ /// The alert's parallax magnitude in horizontal and vertical directions. @property (nonatomic, readonly) UIOffset parallax; -/* - * Title and message label values - */ +#pragma mark - Title & Message Labels @property (nonatomic, readonly) UIFont *titleLabelFont; @property (nonatomic, readonly) UIFont *messageLabelFont; -@property (nonatomic, readonly) UIFont *textFieldFont; @property (nonatomic, readonly) CGFloat labelSpacing; @property (nonatomic, readonly) CGFloat messageLabelBottomSpacing; -/* - * Action-related values - */ +#pragma mark - Actions @property (nonatomic, readonly) CGFloat actionViewHeight; @property (nonatomic, readonly) CGFloat minimumActionViewWidth; // For forced horizontal layout and 3+ buttons @@ -50,10 +43,9 @@ - (UIColor *)textColorForAction:(SDCAlertAction *)action; - (UIFont *)fontForAction:(SDCAlertAction *)action; -/* - * Text field-related values - */ +#pragma mark - Text Fields +@property (nonatomic, readonly) UIFont *textFieldFont; @property (nonatomic, readonly) CGFloat estimatedTextFieldHeight; @property (nonatomic, readonly) CGFloat textFieldBorderWidth; @property (nonatomic, readonly) UIColor *textFieldBorderColor; From cbe62d92ad5b8c0ec489a587ec58ca3b5e4d26a0 Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 15 Oct 2014 19:48:31 -0700 Subject: [PATCH 74/76] Organize 2.0 classes --- SDCAlertView.xcodeproj/project.pbxproj | 60 ++++++++++++++++++++------ 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/SDCAlertView.xcodeproj/project.pbxproj b/SDCAlertView.xcodeproj/project.pbxproj index f6d494d3..e70b025c 100644 --- a/SDCAlertView.xcodeproj/project.pbxproj +++ b/SDCAlertView.xcodeproj/project.pbxproj @@ -261,34 +261,66 @@ D26506EF19C61B8000BF34B9 /* 2.0 */ = { isa = PBXGroup; children = ( + D26506F019C67FC300BF34B9 /* SDCAlertController.h */, + D26506F119C67FC300BF34B9 /* SDCAlertController.m */, + D26506F319C6812600BF34B9 /* SDCAlertAction.m */, + D27C32B419EF68BB00846D1C /* Presentation */, + D27C32B519EF68D400846D1C /* Text Fields */, + D27C32B619EF68FA00846D1C /* Visual Style */, + D27C32B719EF696900846D1C /* Alert View */, D2AE982F19DFBDF50083AB0C /* UIViewController+Current.h */, D2AE983019DFBDF50083AB0C /* UIViewController+Current.m */, + ); + name = 2.0; + sourceTree = ""; + }; + D27C32B419EF68BB00846D1C /* Presentation */ = { + isa = PBXGroup; + children = ( + D259FC1019CEB02100BA6B36 /* SDCAlertPresentationController.h */, + D259FC1119CEB02100BA6B36 /* SDCAlertPresentationController.m */, + D259FC1319CEB0EB00BA6B36 /* SDCAlertControllerTransition.h */, + D259FC1419CEB0EB00BA6B36 /* SDCAlertControllerTransition.m */, + ); + name = Presentation; + sourceTree = ""; + }; + D27C32B519EF68D400846D1C /* Text Fields */ = { + isa = PBXGroup; + children = ( D2D5A76E19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.h */, D2D5A76F19D8A64B00386078 /* SDCAlertControllerTextFieldViewController.m */, D2A6F1C319D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.h */, D2A6F1C419D8A71F00FAF172 /* SDCAlertTextFieldTableViewCell.m */, + ); + name = "Text Fields"; + sourceTree = ""; + }; + D27C32B619EF68FA00846D1C /* Visual Style */ = { + isa = PBXGroup; + children = ( D2988E0519D7960900140116 /* SDCAlertControllerVisualStyle.h */, + D2988E0119D794C100140116 /* SDCAlertControllerDefaultVisualStyle.h */, + D2988E0219D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m */, + ); + name = "Visual Style"; + sourceTree = ""; + }; + D27C32B719EF696900846D1C /* Alert View */ = { + isa = PBXGroup; + children = ( D2666A3E19CFDE2800167157 /* SDCAlertControllerView.h */, D2666A3F19CFDE2800167157 /* SDCAlertControllerView.m */, - D2A5E0CF19D3D6A90034B709 /* SDCAlertCollectionViewCell.h */, - D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */, - D2A6A0D919D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.h */, - D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */, D2666A4119CFDF6700167157 /* SDCAlertControllerScrollView.h */, D2666A4219CFDF6700167157 /* SDCAlertControllerScrollView.m */, D2666A4419CFE0F900167157 /* SDCAlertLabel.h */, D2666A4519CFE0F900167157 /* SDCAlertLabel.m */, - D259FC1019CEB02100BA6B36 /* SDCAlertPresentationController.h */, - D259FC1119CEB02100BA6B36 /* SDCAlertPresentationController.m */, - D259FC1319CEB0EB00BA6B36 /* SDCAlertControllerTransition.h */, - D259FC1419CEB0EB00BA6B36 /* SDCAlertControllerTransition.m */, - D26506F019C67FC300BF34B9 /* SDCAlertController.h */, - D26506F119C67FC300BF34B9 /* SDCAlertController.m */, - D2988E0119D794C100140116 /* SDCAlertControllerDefaultVisualStyle.h */, - D2988E0219D794C100140116 /* SDCAlertControllerDefaultVisualStyle.m */, - D26506F319C6812600BF34B9 /* SDCAlertAction.m */, + D2A5E0CF19D3D6A90034B709 /* SDCAlertCollectionViewCell.h */, + D2A5E0D019D3D6A90034B709 /* SDCAlertCollectionViewCell.m */, + D2A6A0D919D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.h */, + D2A6A0DA19D1456A0022CF39 /* SDCAlertControllerCollectionViewFlowLayout.m */, ); - name = 2.0; + name = "Alert View"; sourceTree = ""; }; D2F8347218EF2C09000BB281 /* Source */ = { From a955a3f08ad64653cd1219f2a1833d72866af23c Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 15 Oct 2014 19:56:47 -0700 Subject: [PATCH 75/76] Update changelog --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a3bfe9c..db8c4dfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # CHANGELOG +# 2.0 + +**What's New:** +- All new API that matches and extends `UIAlertController` +- Ability to always show buttons horizontally or vertically +- Backwards compatible with `SDCAlertView` (1.0) +- More stylistic elements you can style (alert width, button separators, text fields, etc.) + +## 1.4.3 + +**Bug Fixes:** +- Fixes an issue that would not enforce `contentPadding` on the title and message labels properly (#58) + +## 1.4.2 + +**What's New:** +- Extra properties to specify padding and spacing in the alert (#55 - thanks @bcherry) + ## 1.4.1 **Bug Fixes:** From e40349c149a7749daff0a6ec05479c0edd42930c Mon Sep 17 00:00:00 2001 From: Scott Berrevoets Date: Wed, 15 Oct 2014 19:57:24 -0700 Subject: [PATCH 76/76] Update podspec to 2.0 --- SDCAlertView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDCAlertView.podspec b/SDCAlertView.podspec index e20a0463..4bf064c5 100644 --- a/SDCAlertView.podspec +++ b/SDCAlertView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'SDCAlertView' - s.version = '1.4.1' + s.version = '2.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.authors = { 'Scott Berrevoets' => 's.berrevoets@me.com' } s.summary = 'SDCAlertView is a UIAlertView clone with added functionality including a contentView property'