Skip to content
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
1 change: 1 addition & 0 deletions CXAlertView/CXAlertButtonItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ typedef void(^CXAlertButtonHandler)(CXAlertView *alertView, CXAlertButtonItem *b
@property (nonatomic, assign) CXAlertViewButtonType type;
@property (nonatomic, copy) CXAlertButtonHandler action;
@property (nonatomic) BOOL defaultRightLineVisible;
@property (nonatomic) BOOL defaultTopLineVisible;

@end
10 changes: 10 additions & 0 deletions CXAlertView/CXAlertButtonItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ - (void)drawRect:(CGRect)rect
CGContextAddLineToPoint(context, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
CGContextStrokePath(context);
}
if (_defaultTopLineVisible) {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, self.bounds);

CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0.671 green:0.675 blue:0.694 alpha:1.000].CGColor);
CGContextSetLineWidth(context, 2.0);
CGContextMoveToPoint(context, 0,0);
CGContextAddLineToPoint(context, CGRectGetWidth(self.frame), 0);
CGContextStrokePath(context);
}
}

@end
1 change: 1 addition & 0 deletions CXAlertView/CXAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef void(^CXAlertViewHandler)(CXAlertView *alertView);
@property (nonatomic, assign) CGFloat bottomScrollViewHeight;
@property (nonatomic, assign) BOOL showButtonLine;
@property (nonatomic, assign) BOOL showBlurBackground;
@property (nonatomic, assign) BOOL stackButtons;
// Create
- (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle;
- (id)initWithTitle:(NSString *)title contentView:(UIView *)contentView cancelButtonTitle:(NSString *)cancelButtonTitle;
Expand Down
64 changes: 52 additions & 12 deletions CXAlertView/CXAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ - (id)initWithTitle:(NSString *)title contentView:(UIView *)contentView cancelBu

_showButtonLine = YES;
_showBlurBackground = YES;
_stackButtons = YES;
[self setupScrollViews];
if (cancelButtonTitle) {
[self addButtonWithTitle:cancelButtonTitle type:CXAlertViewButtonTypeCancel handler:^(CXAlertView *alertView, CXAlertButtonItem *button) {
Expand Down Expand Up @@ -789,7 +790,8 @@ - (void)addButtonWithTitle:(NSString *)title type:(CXAlertViewButtonType)type ha
[button.titleLabel setNumberOfLines:0];
button.titleLabel.lineBreakMode=BT_LBM;
[button setTitleEdgeInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];


self.buttonHeight = kDefaultButtonHeight;

if ([_buttons count] == 0)
{
Expand All @@ -798,8 +800,11 @@ - (void)addButtonWithTitle:(NSString *)title type:(CXAlertViewButtonType)type ha

[_buttons addObject:button];
[self setMaxSizeForAllButtons];

CGFloat newContentWidth = self.bottomScrollView.contentSize.width + CGRectGetWidth(button.frame);
_bottomScrollView.contentSize = CGSizeMake( newContentWidth, _bottomScrollView.contentSize.height);
}
else
else if ([_buttons count] == 1 || !_stackButtons)
{
// correct first button
CXAlertButtonItem *firstButton = [_buttons objectAtIndex:0];
Expand All @@ -813,27 +818,62 @@ - (void)addButtonWithTitle:(NSString *)title type:(CXAlertViewButtonType)type ha
button.alpha = 0.;

[_buttons addObject:button];

void (^buttomFrameBlock)() = ^{
firstButton.frame = newFrame;
button.alpha = 1.;
button.frame = CGRectMake( last_x, 0, self.containerWidth/2, self.buttonHeight);
[self setMaxSizeForAllButtons];
};

if (self.isVisible) {
[UIView animateWithDuration:0.3 animations:^{
firstButton.frame = newFrame;
button.alpha = 1.;
button.frame = CGRectMake( last_x, 0, self.containerWidth/2, self.buttonHeight);
[self setMaxSizeForAllButtons];
buttomFrameBlock();
}];
}
else {
firstButton.frame = newFrame;
button.alpha = 1.;
button.frame = CGRectMake( last_x, 0, self.containerWidth/2, self.buttonHeight);
buttomFrameBlock();
}

CGFloat newContentWidth = self.bottomScrollView.contentSize.width + CGRectGetWidth(button.frame);
_bottomScrollView.contentSize = CGSizeMake( newContentWidth, _bottomScrollView.contentSize.height);
}
else // stack buttons if more than 2
{
button.frame = CGRectMake(0, 0, self.containerWidth, self.buttonHeight);
button.alpha = 0.;

[_buttons addObject:button];

void (^buttomFrameBlock)() = ^{
CGFloat currentY = 0;
// correct existing buttons, set up new one as well
for (CXAlertButtonItem *buttonItem in _buttons) {
buttonItem.defaultRightLineVisible = NO;
buttonItem.defaultTopLineVisible = YES;
buttonItem.frame = CGRectMake(0, currentY, self.containerWidth, self.buttonHeight);
buttonItem.alpha = 1.;
[buttonItem setNeedsDisplay];
currentY += self.buttonHeight;
}
[self setMaxSizeForAllButtons];
};

if (self.isVisible) {
[UIView animateWithDuration:0.3 animations:^{
buttomFrameBlock();
}];
}
else {
buttomFrameBlock();
}

_bottomScrollViewHeight = self.buttonHeight * _buttons.count;
_bottomScrollView.contentSize = CGSizeMake(self.bottomScrollView.contentSize.width, _bottomScrollViewHeight);
[self updateBottomScrollView];
}

[_bottomScrollView addSubview:button];

CGFloat newContentWidth = self.bottomScrollView.contentSize.width + CGRectGetWidth(button.frame);
_bottomScrollView.contentSize = CGSizeMake( newContentWidth, _bottomScrollView.contentSize.height);
}

- (CXAlertButtonItem *)buttonItemWithType:(CXAlertViewButtonType)type font:(UIFont *)font
Expand Down