diff --git a/README.md b/README.md index c9988b7..234035f 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ SCLAlertView *alert = [[SCLAlertView alloc] init]; [alert showEdit:self title:@"Hello Edit" subTitle:@"This is a more descriptive info text with a edit textbox" closeButtonTitle:@"Done" duration:0.0f]; // Edit [alert showCustom:self image:[UIImage imageNamed:@"git"] color:color title:@"Custom" subTitle:@"Add a custom icon and color for your own type of alert!" closeButtonTitle:@"OK" duration:0.0f]; // Custom [alert showWaiting:self title:@"Waiting..." subTitle:@"Blah de blah de blah, blah. Blah de blah de" closeButtonTitle:nil duration:5.0f]; + +// Using custom alert width +SCLAlertView *alert = [[SCLAlertView alloc] initWithWindowWidth:300.0f]; ``` ###SCLAlertview in a new window. (No UIViewController) @@ -46,6 +49,9 @@ SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow]; [alert showEdit:@"Hello Edit" subTitle:@"This is a more descriptive info text with a edit textbox" closeButtonTitle:@"Done" duration:0.0f]; // Edit [alert showCustom:[UIImage imageNamed:@"git"] color:color title:@"Custom" subTitle:@"Add a custom icon and color for your own type of alert!" closeButtonTitle:@"OK" duration:0.0f]; // Custom [alert showWaiting:@"Waiting..." subTitle:@"Blah de blah de blah, blah. Blah de blah de" closeButtonTitle:nil duration:5.0f]; + +// Using custom alert width +SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:300.0f]; ``` ###New Window: Known issues @@ -79,14 +85,14 @@ SCLAlertView *alert = [[SCLAlertView alloc] init]; ###Add button timer ```Objective-C //The index of the button to add the timer display to. -[alert addTimerToButtonIndex:0]; +[alert addTimerToButtonIndex:0 reverse:NO]; ``` Example: ```Objective-C SCLAlertView *alert = [[SCLAlertView alloc] init]; -[alert addTimerToButtonIndex:0]; +[alert addTimerToButtonIndex:0 reverse:YES]; [alert showInfo:self title:@"Countdown Timer" subTitle:@"This alert has a duration set, and a countdown timer on the Dismiss button to show how long is left." closeButtonTitle:@"Dismiss" duration:10.0f]; ``` diff --git a/SCLAlertView-Objective-C.podspec b/SCLAlertView-Objective-C.podspec index ddabbf2..1059cb7 100644 --- a/SCLAlertView-Objective-C.podspec +++ b/SCLAlertView-Objective-C.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "SCLAlertView-Objective-C" - spec.version = "0.7.7" + spec.version = "0.7.9" spec.summary = "Beautiful animated Alert View. Written in Swift but ported to Objective-C" spec.homepage = "https://github.com/dogo/SCLAlertView" spec.screenshots = "https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot.png", "https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot2.png" diff --git a/SCLAlertView.xcodeproj/project.pbxproj b/SCLAlertView.xcodeproj/project.pbxproj index f58e458..ba35bdf 100644 --- a/SCLAlertView.xcodeproj/project.pbxproj +++ b/SCLAlertView.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 572BB1471B8383B3002DEE38 /* SCLTimerDisplay.m in Sources */ = {isa = PBXBuildFile; fileRef = 572BB1461B8383B3002DEE38 /* SCLTimerDisplay.m */; }; + DD24453C1BAC383600892117 /* SCLTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD24453B1BAC383600892117 /* SCLTextView.m */; settings = {ASSET_TAGS = (); }; }; DD2E172A19FA84B800CBAEC3 /* UIImage+ImageEffects.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2E172919FA84B800CBAEC3 /* UIImage+ImageEffects.m */; }; DD4BA9C119DED8EF008D73EB /* right_answer.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = DD4BA9C019DED8EF008D73EB /* right_answer.mp3 */; }; DD7282B919D6087C00077F54 /* Storyboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DD7282B719D6087C00077F54 /* Storyboard.storyboard */; }; @@ -36,6 +37,8 @@ 572BB1451B8383B3002DEE38 /* SCLTimerDisplay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCLTimerDisplay.h; sourceTree = ""; }; 572BB1461B8383B3002DEE38 /* SCLTimerDisplay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCLTimerDisplay.m; sourceTree = ""; }; DD0D295B19D902DA00881F53 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = SCLAlertViewExample/Info.plist; sourceTree = SOURCE_ROOT; }; + DD24453A1BAC383600892117 /* SCLTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCLTextView.h; sourceTree = ""; }; + DD24453B1BAC383600892117 /* SCLTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCLTextView.m; sourceTree = ""; }; DD2E172819FA84B800CBAEC3 /* UIImage+ImageEffects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ImageEffects.h"; sourceTree = ""; }; DD2E172919FA84B800CBAEC3 /* UIImage+ImageEffects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ImageEffects.m"; sourceTree = ""; }; DD2F03171AAFA4E0007BC507 /* SCLMacros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SCLMacros.h; sourceTree = ""; }; @@ -167,6 +170,8 @@ DD2F03171AAFA4E0007BC507 /* SCLMacros.h */, 572BB1451B8383B3002DEE38 /* SCLTimerDisplay.h */, 572BB1461B8383B3002DEE38 /* SCLTimerDisplay.m */, + DD24453A1BAC383600892117 /* SCLTextView.h */, + DD24453B1BAC383600892117 /* SCLTextView.m */, ); path = SCLAlertView; sourceTree = ""; @@ -275,6 +280,7 @@ DDB15FCB19D5B88A00173158 /* ViewController.m in Sources */, DDB15FD419D5B8DB00173158 /* main.m in Sources */, DDB15FE119D5D85B00173158 /* SCLAlertViewStyleKit.m in Sources */, + DD24453C1BAC383600892117 /* SCLTextView.m in Sources */, 572BB1471B8383B3002DEE38 /* SCLTimerDisplay.m in Sources */, DDB15FD719D5B96500173158 /* SCLAlertView.m in Sources */, DDB15FDB19D5BAA000173158 /* SCLButton.m in Sources */, diff --git a/SCLAlertView/SCLAlertView.h b/SCLAlertView/SCLAlertView.h index 705567f..9407c7d 100755 --- a/SCLAlertView/SCLAlertView.h +++ b/SCLAlertView/SCLAlertView.h @@ -12,6 +12,7 @@ #import #endif #import "SCLButton.h" +#import "SCLTextView.h" typedef NSAttributedString* (^SCLAttributedFormatBlock)(NSString *value); typedef void (^DismissBlock)(void); @@ -178,12 +179,30 @@ typedef NS_ENUM(NSInteger, SCLAlertViewBackground) */ @property (nonatomic) CGRect extensionBounds; +/** Set status bar hidden. + * + * Status bar hidden + */ +@property (nonatomic) BOOL statusBarHidden; + +/** Set status bar style. + * + * Status bar style + */ +@property (nonatomic) UIStatusBarStyle statusBarStyle; + /** Initialize SCLAlertView using a new window. * * Init with new window */ - (instancetype)initWithNewWindow; +/** Initialize SCLAlertView using a new window. + * + * Init with new window with custom width + */ +- (instancetype)initWithNewWindowWidth:(CGFloat)windowWidth; + /** Warns that alerts is gone * * Warns that alerts is gone using block @@ -212,7 +231,7 @@ typedef NS_ENUM(NSInteger, SCLAlertViewBackground) * * @param title The text displayed on the textfield. */ -- (UITextField *)addTextField:(NSString *)title; +- (SCLTextView *)addTextField:(NSString *)title; /** Add a custom Text Field * @@ -227,13 +246,6 @@ typedef NS_ENUM(NSInteger, SCLAlertViewBackground) */ - (void)addTimerToButtonIndex:(NSInteger)buttonIndex reverse:(BOOL)reverse; -/** Set SubTitle Height - * - * @deprecated Deprecated since 0.5.2+ . - * @param value Height of scrollable subtitle text field. - */ -- (void)setSubTitleHeight:(CGFloat)value __deprecated; - /** Set Title font family and size * * @param titleFontFamily The family name used to displayed the title. diff --git a/SCLAlertView/SCLAlertView.m b/SCLAlertView/SCLAlertView.m index 24a0ff4..4a42583 100755 --- a/SCLAlertView/SCLAlertView.m +++ b/SCLAlertView/SCLAlertView.m @@ -22,6 +22,7 @@ #define KEYBOARD_HEIGHT 80 #define PREDICTION_BAR_HEIGHT 40 #define ADD_BUTTON_PADDING 10.0f +#define DEFAULT_WINDOW_WIDTH 240 @interface SCLAlertView () @@ -85,116 +86,37 @@ - (instancetype)init self = [super init]; if (self) { - // Default values - kCircleTopPosition = -12.0f; - kCircleBackgroundTopPosition = -15.0f; - kCircleHeight = 56.0f; - kCircleHeightBackground = 62.0f; - kActivityIndicatorHeight = 40.0f; - kTitleTop = 24.0f; - kTitleHeight = 40.0f; - self.subTitleY = 70.0f; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - self.subTitleHeight = 90.0f; -#pragma clang diagnostic pop - self.circleIconHeight = 20.0f; - self.windowWidth = 240.0f; - self.windowHeight = 178.0f; - self.shouldDismissOnTapOutside = NO; - self.usingNewWindow = NO; - self.canAddObservers = YES; - self.keyboardIsVisible = NO; - self.hideAnimationType = FadeOut; - self.showAnimationType = SlideInFromTop; - self.backgroundType = Shadow; - - // Font - _titleFontFamily = @"HelveticaNeue"; - _bodyTextFontFamily = @"HelveticaNeue"; - _buttonsFontFamily = @"HelveticaNeue-Bold"; - _titleFontSize = 20.0f; - _bodyFontSize = 14.0f; - _buttonsFontSize = 14.0f; - - // Init - _labelTitle = [[UILabel alloc] init]; - _viewText = [[UITextView alloc] init]; - _contentView = [[UIView alloc] init]; - _circleView = [[UIView alloc] init]; - _circleViewBackground = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kCircleHeightBackground, kCircleHeightBackground)]; - _circleIconImageView = [[UIImageView alloc] init]; - _backgroundView = [[UIImageView alloc]initWithFrame:[self mainScreenFrame]]; - _buttons = [[NSMutableArray alloc] init]; - _inputs = [[NSMutableArray alloc] init]; - - // Add Subviews - [self.view addSubview:_contentView]; - [self.view addSubview:_circleViewBackground]; - - // Background View - _backgroundView.userInteractionEnabled = YES; - - // Content View - _contentView.backgroundColor = [UIColor whiteColor]; - _contentView.layer.cornerRadius = 5.0f; - _contentView.layer.masksToBounds = YES; - _contentView.layer.borderWidth = 0.5f; - [_contentView addSubview:_labelTitle]; - [_contentView addSubview:_viewText]; - - // Circle View - _circleViewBackground.backgroundColor = [UIColor whiteColor]; - _circleViewBackground.layer.cornerRadius = _circleViewBackground.frame.size.height / 2; - CGFloat x = (kCircleHeightBackground - kCircleHeight) / 2; - _circleView.frame = CGRectMake(x, x, kCircleHeight, kCircleHeight); - _circleView.layer.cornerRadius = _circleView.frame.size.height / 2; - x = (kCircleHeight - _circleIconHeight) / 2; - _circleIconImageView.frame = CGRectMake(x, x, _circleIconHeight, _circleIconHeight); - [_circleViewBackground addSubview:_circleView]; - [_circleView addSubview:_circleIconImageView]; - - // Title - _labelTitle.numberOfLines = 1; - _labelTitle.textAlignment = NSTextAlignmentCenter; - _labelTitle.font = [UIFont fontWithName:_titleFontFamily size:_titleFontSize]; - _labelTitle.frame = CGRectMake(12.0f, kTitleTop, _windowWidth - 24.0f, kTitleHeight); - - // View text - _viewText.editable = NO; - _viewText.allowsEditingTextAttributes = YES; - _viewText.textAlignment = NSTextAlignmentCenter; - _viewText.font = [UIFont fontWithName:_bodyTextFontFamily size:_bodyFontSize]; - _viewText.frame = CGRectMake(12.0f, _subTitleY, _windowWidth - 24.0f, _subTitleHeight); - - if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) - { - _viewText.textContainerInset = UIEdgeInsetsZero; - _viewText.textContainer.lineFragmentPadding = 0; - } - - // Colors - self.backgroundViewColor = [UIColor whiteColor]; - _labelTitle.textColor = UIColorFromHEX(0x4D4D4D); //Dark Grey - _viewText.textColor = UIColorFromHEX(0x4D4D4D); //Dark Grey - _contentView.layer.borderColor = UIColorFromHEX(0xCCCCCC).CGColor; //Light Grey + [self setupViewWindowWidth:DEFAULT_WINDOW_WIDTH]; + } + return self; +} + +- (instancetype)initWithWindowWidth:(CGFloat)windowWidth +{ + self = [super init]; + if (self) + { + [self setupViewWindowWidth:windowWidth]; } return self; } - (instancetype)initWithNewWindow { - self = [self init]; + self = [self initWithWindowWidth:DEFAULT_WINDOW_WIDTH]; if(self) { - // Create a new one to show the alert - UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[self mainScreenFrame]]; - alertWindow.windowLevel = UIWindowLevelAlert; - alertWindow.backgroundColor = [UIColor clearColor]; - alertWindow.rootViewController = self; - self.SCLAlertWindow = alertWindow; - - self.usingNewWindow = YES; + [self setupNewWindow]; + } + return self; +} + +- (instancetype)initWithNewWindowWidth:(CGFloat)windowWidth +{ + self = [self initWithWindowWidth:windowWidth]; + if(self) + { + [self setupNewWindow]; } return self; } @@ -221,6 +143,114 @@ - (void)removeObservers [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } +#pragma mark - Setup view + +- (void)setupViewWindowWidth:(CGFloat)windowWidth +{ + // Default values + kCircleTopPosition = -12.0f; + kCircleBackgroundTopPosition = -15.0f; + kCircleHeight = 56.0f; + kCircleHeightBackground = 62.0f; + kActivityIndicatorHeight = 40.0f; + kTitleTop = 24.0f; + kTitleHeight = 40.0f; + self.subTitleY = 70.0f; + self.subTitleHeight = 90.0f; + self.circleIconHeight = 20.0f; + self.windowWidth = windowWidth; + self.windowHeight = 178.0f; + self.shouldDismissOnTapOutside = NO; + self.usingNewWindow = NO; + self.canAddObservers = YES; + self.keyboardIsVisible = NO; + self.hideAnimationType = FadeOut; + self.showAnimationType = SlideInFromTop; + self.backgroundType = Shadow; + + // Font + _titleFontFamily = @"HelveticaNeue"; + _bodyTextFontFamily = @"HelveticaNeue"; + _buttonsFontFamily = @"HelveticaNeue-Bold"; + _titleFontSize = 20.0f; + _bodyFontSize = 14.0f; + _buttonsFontSize = 14.0f; + + // Init + _labelTitle = [[UILabel alloc] init]; + _viewText = [[UITextView alloc] init]; + _contentView = [[UIView alloc] init]; + _circleView = [[UIView alloc] init]; + _circleViewBackground = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kCircleHeightBackground, kCircleHeightBackground)]; + _circleIconImageView = [[UIImageView alloc] init]; + _backgroundView = [[UIImageView alloc]initWithFrame:[self mainScreenFrame]]; + _buttons = [[NSMutableArray alloc] init]; + _inputs = [[NSMutableArray alloc] init]; + + // Add Subviews + [self.view addSubview:_contentView]; + [self.view addSubview:_circleViewBackground]; + + // Background View + _backgroundView.userInteractionEnabled = YES; + + // Content View + _contentView.backgroundColor = [UIColor whiteColor]; + _contentView.layer.cornerRadius = 5.0f; + _contentView.layer.masksToBounds = YES; + _contentView.layer.borderWidth = 0.5f; + [_contentView addSubview:_labelTitle]; + [_contentView addSubview:_viewText]; + + // Circle View + _circleViewBackground.backgroundColor = [UIColor whiteColor]; + _circleViewBackground.layer.cornerRadius = _circleViewBackground.frame.size.height / 2; + CGFloat x = (kCircleHeightBackground - kCircleHeight) / 2; + _circleView.frame = CGRectMake(x, x, kCircleHeight, kCircleHeight); + _circleView.layer.cornerRadius = _circleView.frame.size.height / 2; + x = (kCircleHeight - _circleIconHeight) / 2; + _circleIconImageView.frame = CGRectMake(x, x, _circleIconHeight, _circleIconHeight); + [_circleViewBackground addSubview:_circleView]; + [_circleView addSubview:_circleIconImageView]; + + // Title + _labelTitle.numberOfLines = 1; + _labelTitle.textAlignment = NSTextAlignmentCenter; + _labelTitle.font = [UIFont fontWithName:_titleFontFamily size:_titleFontSize]; + _labelTitle.frame = CGRectMake(12.0f, kTitleTop, _windowWidth - 24.0f, kTitleHeight); + + // View text + _viewText.editable = NO; + _viewText.allowsEditingTextAttributes = YES; + _viewText.textAlignment = NSTextAlignmentCenter; + _viewText.font = [UIFont fontWithName:_bodyTextFontFamily size:_bodyFontSize]; + _viewText.frame = CGRectMake(12.0f, _subTitleY, _windowWidth - 24.0f, _subTitleHeight); + + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) + { + _viewText.textContainerInset = UIEdgeInsetsZero; + _viewText.textContainer.lineFragmentPadding = 0; + } + + // Colors + self.backgroundViewColor = [UIColor whiteColor]; + _labelTitle.textColor = UIColorFromHEX(0x4D4D4D); //Dark Grey + _viewText.textColor = UIColorFromHEX(0x4D4D4D); //Dark Grey + _contentView.layer.borderColor = UIColorFromHEX(0xCCCCCC).CGColor; //Light Grey +} + +- (void)setupNewWindow +{ + // Create a new one to show the alert + UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[self mainScreenFrame]]; + alertWindow.windowLevel = UIWindowLevelAlert; + alertWindow.backgroundColor = [UIColor clearColor]; + alertWindow.rootViewController = self; + self.SCLAlertWindow = alertWindow; + + self.usingNewWindow = YES; +} + #pragma mark - Modal Validation - (BOOL)isModal @@ -245,7 +275,7 @@ - (void)viewWillLayoutSubviews if (SYSTEM_VERSION_LESS_THAN(@"8.0")) { // iOS versions before 7.0 did not switch the width and height on device roration - if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) + if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { CGSize ssz = sz; sz = CGSizeMake(ssz.height, ssz.width); @@ -294,11 +324,11 @@ - (void)viewWillLayoutSubviews // Text fields CGFloat y = (_labelTitle.text == nil) ? (kCircleHeight - 20.0f) : 74.0f; y += _subTitleHeight + 14.0f; - for (UITextField *textField in _inputs) + for (SCLTextView *textField in _inputs) { - textField.frame = CGRectMake(12.0f, y, _windowWidth - 24.0f, 30.0f); + textField.frame = CGRectMake(12.0f, y, _windowWidth - 24.0f, textField.frame.size.height); textField.layer.cornerRadius = 3.0f; - y += 40.0f; + y += textField.frame.size.height + 10.0f; } // Buttons @@ -311,6 +341,18 @@ - (void)viewWillLayoutSubviews } } +#pragma mark - UIViewController + +- (BOOL)prefersStatusBarHidden +{ + return self.statusBarHidden; +} + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return self.statusBarStyle; +} + #pragma mark - Handle gesture - (void)handleTap:(UITapGestureRecognizer *)gesture @@ -319,10 +361,10 @@ - (void)handleTap:(UITapGestureRecognizer *)gesture { BOOL hide = _shouldDismissOnTapOutside; - for(UITextField *txt in _inputs) + for(SCLTextView *txt in _inputs) { // Check if there is any keyboard on screen and dismiss - if ([txt isEditing]) + if (txt.editing) { [txt resignFirstResponder]; hide = NO; @@ -447,23 +489,17 @@ - (void)addActivityIndicatorView #pragma mark - TextField -- (UITextField *)addTextField:(NSString *)title +- (SCLTextView *)addTextField:(NSString *)title { [self addObservers]; - // Update view height - self.windowHeight += 40.0f; - // Add text field - UITextField *txt = [[UITextField alloc] init]; - txt.delegate = self; - txt.returnKeyType = UIReturnKeyDone; - txt.borderStyle = UITextBorderStyleRoundedRect; + SCLTextView *txt = [[SCLTextView alloc] init]; txt.font = [UIFont fontWithName:_bodyTextFontFamily size:_bodyFontSize]; - txt.autocapitalizationType = UITextAutocapitalizationTypeWords; - txt.clearButtonMode = UITextFieldViewModeWhileEditing; - txt.layer.masksToBounds = YES; - txt.layer.borderWidth = 1.0f; + txt.delegate = self; + + // Update view height + self.windowHeight += txt.bounds.size.height + 10.0f; if (title != nil) { @@ -478,7 +514,7 @@ - (UITextField *)addTextField:(NSString *)title if (_inputs.count > 1) { NSUInteger indexOfCurrentField = [_inputs indexOfObject:txt]; - UITextField *priorField = _inputs[indexOfCurrentField - 1]; + SCLTextView *priorField = _inputs[indexOfCurrentField - 1]; priorField.returnKeyType = UIReturnKeyNext; } return txt; @@ -487,7 +523,7 @@ - (UITextField *)addTextField:(NSString *)title - (void)addCustomTextField:(UITextField *)textField { // Update view height - self.windowHeight += 40.0f; + self.windowHeight += textField.bounds.size.height + 10.0f; [_contentView addSubview:textField]; [_inputs addObject:textField]; @@ -508,7 +544,7 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField { // If this is the last object in the inputs array, resign first responder // as the form is at the end. - if (textField == [_inputs lastObject]) + if (textField == _inputs.lastObject) { [textField resignFirstResponder]; } @@ -550,7 +586,7 @@ - (void)keyboardWillHide:(NSNotification *)notification - (SCLButton *)addButton:(NSString *)title { // Add button - SCLButton *btn = [[SCLButton alloc] init]; + SCLButton *btn = [[SCLButton alloc] initWithWindowWidth:self.windowWidth]; btn.layer.masksToBounds = YES; [btn setTitle:title forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont fontWithName:_buttonsFontFamily size:_buttonsFontSize]; @@ -587,7 +623,7 @@ - (SCLButton *)addButton:(NSString *)title actionBlock:(SCLActionBlock)action btn.buttonFormatBlock = _buttonFormatBlock; } - btn.actionType = Block; + btn.actionType = SCLBlock; btn.actionBlock = action; [btn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; @@ -605,7 +641,7 @@ - (SCLButton *)addButton:(NSString *)title validationBlock:(SCLValidationBlock)v - (SCLButton *)addButton:(NSString *)title target:(id)target selector:(SEL)selector { SCLButton *btn = [self addButton:title]; - btn.actionType = Selector; + btn.actionType = SCLSelector; btn.target = target; btn.selector = selector; [btn addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; @@ -628,12 +664,12 @@ - (void)buttonTapped:(SCLButton *)btn [self hideView]; } - if (btn.actionType == Block) + if (btn.actionType == SCLBlock) { if (btn.actionBlock) btn.actionBlock(); } - else if (btn.actionType == Selector) + else if (btn.actionType == SCLSelector) { UIControl *ctrl = [[UIControl alloc] init]; [ctrl sendAction:btn.selector to:btn.target forEvent:nil]; @@ -663,7 +699,7 @@ - (SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)ima if(_usingNewWindow) { // Save previous window - self.previousWindow = [[UIApplication sharedApplication] keyWindow]; + self.previousWindow = [UIApplication sharedApplication].keyWindow; self.backgroundView.frame = _SCLAlertWindow.bounds; // Add window subview @@ -786,18 +822,12 @@ - (SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)ima if (ht < _subTitleHeight) { self.windowHeight -= (_subTitleHeight - ht); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" self.subTitleHeight = ht; -#pragma clang diagnostic pop } else { self.windowHeight += (ht - _subTitleHeight); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" self.subTitleHeight = ht; -#pragma clang diagnostic pop } } else @@ -808,18 +838,12 @@ - (SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)ima if (ht < _subTitleHeight) { self.windowHeight -= (_subTitleHeight - ht); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" self.subTitleHeight = ht; -#pragma clang diagnostic pop } else { self.windowHeight += (ht - _subTitleHeight); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" self.subTitleHeight = ht; -#pragma clang diagnostic pop } } _viewText.frame = CGRectMake(12.0f, _subTitleY, _windowWidth - 24.0f, _subTitleHeight); @@ -827,10 +851,7 @@ - (SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)ima else { // Subtitle is nil, we can move the title to center and remove it from superView -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" self.subTitleHeight = 0.0f; -#pragma clang diagnostic pop self.windowHeight -= _viewText.frame.size.height; [_viewText removeFromSuperview]; @@ -873,7 +894,7 @@ - (SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)ima self.circleIconImageView.image = iconImage; } - for (UITextField *textField in _inputs) + for (SCLTextView *textField in _inputs) { textField.layer.borderColor = viewColor.CGColor; } @@ -904,9 +925,9 @@ - (SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)ima { [durationTimer invalidate]; - if (buttonTimer && [_buttons count] > 0) { + if (buttonTimer && _buttons.count > 0) { - SCLButton *btn = [_buttons objectAtIndex:buttonTimer.buttonIndex]; + SCLButton *btn = _buttons[buttonTimer.buttonIndex]; btn.timer = buttonTimer; [buttonTimer startTimerWithTimeLimit:duration completed:^{ [self buttonTapped:btn]; @@ -1055,7 +1076,7 @@ - (CGRect)mainScreenFrame - (BOOL)isAppExtension { - return [[[NSBundle mainBundle] executablePath] rangeOfString:@".appex/"].location != NSNotFound; + return [[NSBundle mainBundle].executablePath rangeOfString:@".appex/"].location != NSNotFound; } #pragma mark - Background Effects @@ -1070,7 +1091,7 @@ - (void)makeShadowBackground - (void)makeBlurBackground { - UIView *appView = (_usingNewWindow) ? [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject] : _rootViewController.view; + UIView *appView = (_usingNewWindow) ? [UIApplication sharedApplication].keyWindow.subviews.lastObject : _rootViewController.view; UIImage *image = [UIImage convertViewToImage:appView]; UIImage *blurSnapshotImage = [image applyBlurWithRadius:5.0f tintColor:[UIColor colorWithWhite:0.2f diff --git a/SCLAlertView/SCLButton.h b/SCLAlertView/SCLButton.h index 7146fe9..1d4b496 100644 --- a/SCLAlertView/SCLButton.h +++ b/SCLAlertView/SCLButton.h @@ -24,9 +24,9 @@ typedef NSDictionary* (^ButtonFormatBlock)(void); // Action Types typedef NS_ENUM(NSInteger, SCLActionType) { - None, - Selector, - Block + SCLNone, + SCLSelector, + SCLBlock }; /** Set button action type. @@ -93,4 +93,9 @@ typedef NS_ENUM(NSInteger, SCLActionType) */ @property (nonatomic) SCLTimerDisplay *timer; +/** Init method + * + */ +- (instancetype)initWithWindowWidth:(CGFloat)windowWidth; + @end diff --git a/SCLAlertView/SCLButton.m b/SCLAlertView/SCLButton.m index 4063a41..db84b75 100644 --- a/SCLAlertView/SCLButton.m +++ b/SCLAlertView/SCLButton.m @@ -9,6 +9,8 @@ #import "SCLButton.h" #import "SCLTimerDisplay.h" +#define MARGIN_BUTTON 12.0f +#define DEFAULT_WINDOW_WIDTH 240 #define MIN_HEIGHT 35.0f @implementation SCLButton @@ -18,7 +20,17 @@ - (instancetype)init self = [super init]; if (self) { - [self setup]; + [self setupWithWindowWidth:DEFAULT_WINDOW_WIDTH]; + } + return self; +} + +- (instancetype)initWithWindowWidth:(CGFloat)windowWidth +{ + self = [super init]; + if (self) + { + [self setupWithWindowWidth:windowWidth]; } return self; } @@ -28,7 +40,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder self = [super initWithCoder:aDecoder]; if(self) { - [self setup]; + [self setupWithWindowWidth:DEFAULT_WINDOW_WIDTH]; } return self; } @@ -38,14 +50,14 @@ - (instancetype)initWithFrame:(CGRect)frame self = [super initWithFrame:frame]; if (self) { - [self setup]; + [self setupWithWindowWidth:DEFAULT_WINDOW_WIDTH]; } return self; } -- (void)setup +- (void)setupWithWindowWidth:(CGFloat)windowWidth { - self.frame = CGRectMake(0.0f, 0.0f, 216.0f, 35.0f); + self.frame = CGRectMake(0.0f, 0.0f, windowWidth - (MARGIN_BUTTON * 2), MIN_HEIGHT); self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping; self.titleLabel.textAlignment = NSTextAlignmentCenter; } @@ -54,10 +66,13 @@ - (void)setTitle:(NSString *)title forState:(UIControlState)state { [super setTitle:title forState:state]; self.titleLabel.numberOfLines = 0; + // Update title frame. [self.titleLabel sizeToFit]; + // Get height needed to display title label completely CGFloat buttonHeight = MAX(self.titleLabel.frame.size.height, MIN_HEIGHT); + // Update button frame self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, buttonHeight); } diff --git a/SCLAlertView/SCLTextView.h b/SCLAlertView/SCLTextView.h new file mode 100644 index 0000000..4f91486 --- /dev/null +++ b/SCLAlertView/SCLTextView.h @@ -0,0 +1,17 @@ +// +// SCLTextView.h +// SCLAlertView +// +// Created by Diogo Autilio on 9/18/15. +// Copyright © 2015 AnyKey Entertainment. All rights reserved. +// + +#if defined(__has_feature) && __has_feature(modules) +@import UIKit; +#else +#import +#endif + +@interface SCLTextView : UITextField + +@end diff --git a/SCLAlertView/SCLTextView.m b/SCLAlertView/SCLTextView.m new file mode 100644 index 0000000..4d5ad69 --- /dev/null +++ b/SCLAlertView/SCLTextView.m @@ -0,0 +1,56 @@ +// +// SCLTextView.m +// SCLAlertView +// +// Created by Diogo Autilio on 9/18/15. +// Copyright © 2015 AnyKey Entertainment. All rights reserved. +// + +#import "SCLTextView.h" + +#define MIN_HEIGHT 30.0f + +@implementation SCLTextView + +- (instancetype)init +{ + self = [super init]; + if (self) + { + [self setup]; + } + return self; +} + +- (instancetype)initWithCoder:(NSCoder *)aDecoder +{ + self = [super initWithCoder:aDecoder]; + if(self) + { + [self setup]; + } + return self; +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) + { + [self setup]; + } + return self; +} + +- (void)setup +{ + self.frame = CGRectMake(0.0f, 0.0f, 0.0f, MIN_HEIGHT); + self.returnKeyType = UIReturnKeyDone; + self.borderStyle = UITextBorderStyleRoundedRect; + self.autocapitalizationType = UITextAutocapitalizationTypeWords; + self.clearButtonMode = UITextFieldViewModeWhileEditing; + self.layer.masksToBounds = YES; + self.layer.borderWidth = 1.0f; +} + +@end diff --git a/SCLAlertView/SCLTimerDisplay.m b/SCLAlertView/SCLTimerDisplay.m index bcec598..cb055e4 100644 --- a/SCLAlertView/SCLTimerDisplay.m +++ b/SCLAlertView/SCLTimerDisplay.m @@ -22,7 +22,7 @@ @implementation SCLTimerDisplay @synthesize currentAngle; -- (id)initWithFrame:(CGRect)frame +- (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) diff --git a/SCLAlertViewExample/ViewController.m b/SCLAlertViewExample/ViewController.m index 8fef625..204eef1 100644 --- a/SCLAlertViewExample/ViewController.m +++ b/SCLAlertViewExample/ViewController.m @@ -56,7 +56,7 @@ - (IBAction)showSuccess:(id)sender NSLog(@"Second button tapped"); }]; - alert.soundURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/right_answer.mp3", [[NSBundle mainBundle] resourcePath]]]; + alert.soundURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/right_answer.mp3", [NSBundle mainBundle].resourcePath]]; [alert showSuccess:kSuccessTitle subTitle:kSubtitle closeButtonTitle:kButtonTitle duration:0.0f]; } @@ -103,7 +103,7 @@ - (IBAction)showEdit:(id)sender { SCLAlertView *alert = [[SCLAlertView alloc] init]; - UITextField *textField = [alert addTextField:@"Enter your name"]; + SCLTextView *textField = [alert addTextField:@"Enter your name"]; [alert addButton:@"Show Name" actionBlock:^(void) { NSLog(@"Text value: %@", textField.text); @@ -128,7 +128,7 @@ - (IBAction)showAdvanced:(id)sender NSLog(@"Second button tapped"); }]; - UITextField *textField = [alert addTextField:@"Enter your name"]; + SCLTextView *textField = [alert addTextField:@"Enter your name"]; [alert addButton:@"Show Name" actionBlock:^(void) { NSLog(@"Text value: %@", textField.text); @@ -184,10 +184,10 @@ - (IBAction)showValidation:(id)sender { SCLAlertView *alert = [[SCLAlertView alloc] init]; - UITextField *evenField = [alert addTextField:@"Enter an even number"]; + SCLTextView *evenField = [alert addTextField:@"Enter an even number"]; evenField.keyboardType = UIKeyboardTypeNumberPad; - UITextField *oddField = [alert addTextField:@"Enter an odd number"]; + SCLTextView *oddField = [alert addTextField:@"Enter an odd number"]; oddField.keyboardType = UIKeyboardTypeNumberPad; [alert addButton:@"Test Validation" validationBlock:^BOOL{ @@ -205,7 +205,7 @@ - (IBAction)showValidation:(id)sender return NO; } - NSInteger evenFieldEntry = [evenField.text integerValue]; + NSInteger evenFieldEntry = (evenField.text).integerValue; BOOL evenFieldPassedValidation = evenFieldEntry % 2 == 0; if (!evenFieldPassedValidation) @@ -215,7 +215,7 @@ - (IBAction)showValidation:(id)sender return NO; } - NSInteger oddFieldEntry = [oddField.text integerValue]; + NSInteger oddFieldEntry = (oddField.text).integerValue; BOOL oddFieldPassedValidation = oddFieldEntry % 2 == 1; if (!oddFieldPassedValidation) @@ -236,8 +236,8 @@ - (IBAction)showWaiting:(id)sender { SCLAlertView *alert = [[SCLAlertView alloc] init]; - [alert setShowAnimationType:SlideInToCenter]; - [alert setHideAnimationType:SlideOutFromCenter]; + alert.showAnimationType = SlideInToCenter; + alert.hideAnimationType = SlideOutFromCenter; alert.backgroundType = Transparent;