Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a setting that allows two buttons to be stacked verticaly #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NYAlertViewController/NYAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
13 changes: 10 additions & 3 deletions NYAlertViewController/NYAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];

Expand Down
11 changes: 11 additions & 0 deletions NYAlertViewController/NYAlertViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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

Expand Down
13 changes: 13 additions & 0 deletions NYAlertViewController/NYAlertViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down