diff --git a/NYAlertViewController/NYAlertView.h b/NYAlertViewController/NYAlertView.h index f220c85..63311a5 100644 --- a/NYAlertViewController/NYAlertView.h +++ b/NYAlertViewController/NYAlertView.h @@ -28,6 +28,7 @@ typedef NS_ENUM(NSInteger, NYAlertViewButtonType) { @interface NYAlertView : UIView +@property (nonatomic) NSInteger titleNumberOfLines; @property UILabel *titleLabel; @property UITextView *messageTextView; @property (nonatomic) UIView *contentView; @@ -43,6 +44,7 @@ typedef NS_ENUM(NSInteger, NYAlertViewButtonType) { @property (nonatomic) UIColor *destructiveButtonColor; @property (nonatomic) UIColor *destructiveButtonTitleColor; +@property (nonatomic) BOOL showsButtonsVerticaly; @property (nonatomic) CGFloat buttonCornerRadius; @property (nonatomic) CGFloat maximumWidth; diff --git a/NYAlertViewController/NYAlertView.m b/NYAlertViewController/NYAlertView.m index 227d52f..3436c80 100644 --- a/NYAlertViewController/NYAlertView.m +++ b/NYAlertViewController/NYAlertView.m @@ -238,6 +238,8 @@ - (instancetype)initWithFrame:(CGRect)frame { if (self) { self.maximumWidth = 480.0f; + self.titleNumberOfLines = 2; //default value for title lines number + _alertBackgroundView = [[UIView alloc] initWithFrame:CGRectZero]; [self.alertBackgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; self.alertBackgroundView.backgroundColor = [UIColor colorWithWhite:0.97f alpha:1.0f]; @@ -246,7 +248,7 @@ - (instancetype)initWithFrame:(CGRect)frame { _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; [self.titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; - self.titleLabel.numberOfLines = 2; + self.titleLabel.numberOfLines = self.titleNumberOfLines; self.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; self.titleLabel.textAlignment = NSTextAlignmentCenter; self.titleLabel.textColor = [UIColor darkGrayColor]; @@ -373,6 +375,11 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { return NO; } +- (void)setTitleNumberOfLines:(NSInteger)titleNumberOfLines +{ + self.titleLabel.numberOfLines = titleNumberOfLines; +} + - (void)setMaximumWidth:(CGFloat)maximumWidth { _maximumWidth = maximumWidth; self.alertBackgroundWidthConstraint.constant = maximumWidth; @@ -494,8 +501,8 @@ - (void)setActionButtons:(NSArray *)actionButtons { _actionButtons = actionButtons; - // If there are 2 actions, display the buttons next to each other. Otherwise, stack the buttons vertically at full width - if ([actionButtons count] == 2) { + // If there are 2 actions and showsButtonsVerticaly is not set to YES, display the buttons next to each other. Otherwise, stack the buttons vertically at full width + if ([actionButtons count] == 2 && !self.showsButtonsVerticaly) { UIButton *firstButton = actionButtons[0]; UIButton *lastButton = actionButtons[1]; diff --git a/NYAlertViewController/NYAlertViewController.h b/NYAlertViewController/NYAlertViewController.h index 88fb990..f8ba5c1 100644 --- a/NYAlertViewController/NYAlertViewController.h +++ b/NYAlertViewController/NYAlertViewController.h @@ -34,6 +34,12 @@ typedef NS_ENUM(NSInteger, NYAlertViewControllerTransitionStyle) { */ + (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message; +/** + The message displayed under the alert view's title + */ +@property (nonatomic) NSInteger titleLabelNumberOfLines; + + /** The message displayed under the alert view's title */ @@ -44,6 +50,11 @@ typedef NS_ENUM(NSInteger, NYAlertViewControllerTransitionStyle) { */ @property (nonatomic) BOOL showsStatusBar; +/** + A Boolean value that determines whether the Buttons should be stacked verticaly even if there are just two buttons + */ +@property (nonatomic) BOOL showsButtonsVerticaly; + /** The custom view displayed in the presented alert view diff --git a/NYAlertViewController/NYAlertViewController.m b/NYAlertViewController/NYAlertViewController.m index 7d3e8ab..d705c99 100644 --- a/NYAlertViewController/NYAlertViewController.m +++ b/NYAlertViewController/NYAlertViewController.m @@ -385,6 +385,19 @@ - (BOOL)prefersStatusBarHidden { return !self.showsStatusBar; } +- (void)setTitleLabelNumberOfLines:(NSInteger)titleLabelNumberOfLines +{ + self.view.titleNumberOfLines = titleLabelNumberOfLines; +} + +- (BOOL)showsButtonsVerticaly { + return self.view.showsButtonsVerticaly; +} + +- (void)setShowsButtonsVerticaly:(BOOL)showsButtonsVerticaly { + self.view.showsButtonsVerticaly = showsButtonsVerticaly; +} + - (CGFloat)maximumWidth { return self.view.maximumWidth; } diff --git a/NYAlertViewControllerDemo/NYAlertViewDemo/DemoViewController.m b/NYAlertViewControllerDemo/NYAlertViewDemo/DemoViewController.m index d0d317b..601b2e5 100644 --- a/NYAlertViewControllerDemo/NYAlertViewDemo/DemoViewController.m +++ b/NYAlertViewControllerDemo/NYAlertViewDemo/DemoViewController.m @@ -76,6 +76,8 @@ - (void)showCustomAlertViewWithActionCount:(NSInteger)actionCount { alertViewController.messageFont = [UIFont fontWithName:@"AvenirNext-Regular" size:alertViewController.messageFont.pointSize]; alertViewController.buttonTitleFont = [UIFont fontWithName:@"AvenirNext-Regular" size:alertViewController.buttonTitleFont.pointSize]; alertViewController.cancelButtonTitleFont = [UIFont fontWithName:@"AvenirNext-Medium" size:alertViewController.cancelButtonTitleFont.pointSize]; + //Force the buttons to be shown verticaly + alertViewController.showsButtonsVerticaly = YES; for (int i = 0; i < actionCount; i++) { NSString *actionTitle = [NSString stringWithFormat:NSLocalizedString(@"Action %d", nil), i + 1];