From 4dedf86f024fd1e7d8eb20bf070618662b537801 Mon Sep 17 00:00:00 2001 From: RJ Walsh Date: Tue, 24 Jun 2014 10:58:48 -0700 Subject: [PATCH 1/3] Support for vertical button Layout --- CXAlertView/CXAlertButtonItem.h | 2 +- CXAlertView/CXAlertButtonItem.m | 11 ++++ CXAlertView/CXAlertView.h | 1 + CXAlertView/CXAlertView.m | 90 +++++++++++++++++++++------------ 4 files changed, 71 insertions(+), 33 deletions(-) diff --git a/CXAlertView/CXAlertButtonItem.h b/CXAlertView/CXAlertButtonItem.h index 0372d07..c7b12b9 100644 --- a/CXAlertView/CXAlertButtonItem.h +++ b/CXAlertView/CXAlertButtonItem.h @@ -20,10 +20,10 @@ typedef void(^CXAlertButtonHandler)(CXAlertView *alertView, CXAlertButtonItem *b @interface CXAlertButtonItem : UIButton - @property (nonatomic, copy) NSString *title; @property (nonatomic, assign) CXAlertViewButtonType type; @property (nonatomic, copy) CXAlertButtonHandler action; @property (nonatomic) BOOL defaultRightLineVisible; +@property (nonatomic, assign) BOOL bottomLineVisible; @end diff --git a/CXAlertView/CXAlertButtonItem.m b/CXAlertView/CXAlertButtonItem.m index 16329ad..b865e09 100644 --- a/CXAlertView/CXAlertButtonItem.m +++ b/CXAlertView/CXAlertButtonItem.m @@ -32,6 +32,17 @@ - (void)drawRect:(CGRect)rect CGContextAddLineToPoint(context, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)); CGContextStrokePath(context); } + + if (self.bottomLineVisible) { + 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, 1.0); + CGContextMoveToPoint(context, 0, CGRectGetHeight(self.frame)); + CGContextAddLineToPoint(context, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)); + CGContextStrokePath(context); + } } @end diff --git a/CXAlertView/CXAlertView.h b/CXAlertView/CXAlertView.h index 14347ff..7e8a10b 100644 --- a/CXAlertView/CXAlertView.h +++ b/CXAlertView/CXAlertView.h @@ -46,6 +46,7 @@ typedef void(^CXAlertViewHandler)(CXAlertView *alertView); @property (nonatomic, assign) CGFloat contentScrollViewMinHeight; @property (nonatomic, assign) CGFloat bottomScrollViewHeight; @property (nonatomic, assign) BOOL showButtonLine; +@property (nonatomic, assign) BOOL layoutButtonsVertical; @property (nonatomic, assign) BOOL showBlurBackground; // Create - (id)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle; diff --git a/CXAlertView/CXAlertView.m b/CXAlertView/CXAlertView.m index 6b3533f..15699d6 100644 --- a/CXAlertView/CXAlertView.m +++ b/CXAlertView/CXAlertView.m @@ -752,30 +752,45 @@ -(CGFloat)heightThatFitsButton:(CXAlertButtonItem*)button UIFont *fnt=[self fontForButtonType:button.type]; CGFloat btht=[button.title sizeWithFont:fnt constrainedToSize:desiredSize lineBreakMode:BT_LBM].height; - return btht+22; + return ceil(btht)+22; } -(void)setMaxSizeForAllButtons { - CGFloat maxHeight=22; - for(CXAlertButtonItem *button in self.buttons) - { - CGFloat ht=[self heightThatFitsButton:button]; - if(ht>maxHeight) - { - maxHeight=ht; - } - } - - for(CXAlertButtonItem *button in self.buttons) - { - CGRect rect=button.frame; - rect.size.height=maxHeight; - button.frame=rect; - } + CGFloat maxHeight=22; + for(CXAlertButtonItem *button in self.buttons) + { + CGFloat ht=[self heightThatFitsButton:button]; + if(ht>maxHeight) + { + maxHeight=ht; + } + } + + if (self.layoutButtonsVertical) { + CGFloat ht = 0; + for(CXAlertButtonItem *button in self.buttons) { + CGRect rect = button.frame; + rect.size.height = maxHeight; + rect.origin.y = ht; + ht += maxHeight; + button.frame = rect; + } + _bottomScrollView.contentSize = CGSizeMake(self.frame.size.width, ht); + _bottomScrollViewHeight = ht; + } else { - _bottomScrollView.contentSize = CGSizeMake( _bottomScrollView.contentSize.width, maxHeight); - _bottomScrollViewHeight=maxHeight; + + for(CXAlertButtonItem *button in self.buttons) + { + CGRect rect=button.frame; + rect.size.height=maxHeight; + button.frame=rect; + } + + _bottomScrollView.contentSize = CGSizeMake( _bottomScrollView.contentSize.width, maxHeight); + _bottomScrollViewHeight=maxHeight; + } } - (void)addButtonWithTitle:(NSString *)title type:(CXAlertViewButtonType)type handler:(CXAlertButtonHandler)handler font:(UIFont *)font @@ -785,6 +800,7 @@ - (void)addButtonWithTitle:(NSString *)title type:(CXAlertViewButtonType)type ha button.action = handler; button.type = type; button.defaultRightLineVisible = _showButtonLine; + button.bottomLineVisible = NO; [button setTitle:title forState:UIControlStateNormal]; button.titleLabel.textAlignment=TA_CENTER; @@ -793,16 +809,25 @@ - (void)addButtonWithTitle:(NSString *)title type:(CXAlertViewButtonType)type ha [button setTitleEdgeInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)]; - if ([_buttons count] == 0) - { + if ([_buttons count] == 0) { button.defaultRightLineVisible = NO; button.frame = CGRectMake( 0, 0, self.containerWidth, self.buttonHeight); [_buttons addObject:button]; [self setMaxSizeForAllButtons]; - } - else - { + } else if (self.layoutButtonsVertical) { + // Vertical buttons are simpler - just grow downwards instead + CXAlertButtonItem *lastButton = self.buttons.lastObject; + lastButton.bottomLineVisible = _showButtonLine; + + CGRect lastFrame = lastButton.frame; + lastFrame.origin.y += self.buttonHeight; + button.frame = lastFrame; + button.defaultRightLineVisible = NO; + + [self.buttons addObject:button]; + [self setMaxSizeForAllButtons]; + } else { // correct first button CXAlertButtonItem *firstButton = [_buttons objectAtIndex:0]; firstButton.defaultRightLineVisible = _showButtonLine; @@ -817,19 +842,20 @@ - (void)addButtonWithTitle:(NSString *)title type:(CXAlertViewButtonType)type ha [_buttons addObject:button]; + void (^setButtonFrames)() = ^{ + 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]; + setButtonFrames(); }]; } else { - firstButton.frame = newFrame; - button.alpha = 1.; - button.frame = CGRectMake( last_x, 0, self.containerWidth/2, self.buttonHeight); - [self setMaxSizeForAllButtons]; + setButtonFrames(); } } From e4d317041c9b6ad30cb46f2c6facd1a930828576 Mon Sep 17 00:00:00 2001 From: RJ Walsh Date: Thu, 26 Jun 2014 09:17:00 -0700 Subject: [PATCH 2/3] Bunmp to 1.0.2 --- CXAlertView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CXAlertView.podspec b/CXAlertView.podspec index 8596a32..ed45fd6 100644 --- a/CXAlertView.podspec +++ b/CXAlertView.podspec @@ -5,7 +5,7 @@ Pod::Spec.new do |s| s.homepage = "https://github.com/ChrisXu1221/CXAlertView" s.license = 'MIT' s.author = { "ChrisXu" => "taterctl@gmail.com" } - s.source = { :git => "https://github.com/czeluff/CXAlertView.git", :tag => "1.0.1" } + s.source = { :git => "https://github.com/czeluff/CXAlertView.git", :tag => "1.0.2" } s.source_files = 'CXAlertView/*.{h,m}' s.platform = :ios, '5.0' s.framework = 'QuartzCore', 'CoreGraphics', 'Accelerate' From 36c54affc81b63506a45564327cea02a170d2b85 Mon Sep 17 00:00:00 2001 From: RJ Walsh Date: Thu, 26 Jun 2014 09:22:28 -0700 Subject: [PATCH 3/3] Actually bump to 1.0.2 --- CXAlertView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CXAlertView.podspec b/CXAlertView.podspec index ed45fd6..64da230 100644 --- a/CXAlertView.podspec +++ b/CXAlertView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CXAlertView" - s.version = "1.0.1" + s.version = "1.0.2" s.summary = "Custom alertView which allow you to add view as main content." s.homepage = "https://github.com/ChrisXu1221/CXAlertView" s.license = 'MIT'