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 SIAlertView/SIAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView);
- (void)setCancelButtonImage:(UIImage *)cancelButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (void)setDestructiveButtonImage:(UIImage *)destructiveButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

@property (nonatomic) BOOL isNeedHorizonLayout;
- (id)initWithTitle:(NSString *)title andMessage:(NSString *)message;
- (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type handler:(SIAlertViewHandler)handler;

Expand Down
55 changes: 55 additions & 0 deletions SIAlertView/SIAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,20 @@ - (void)validateLayout
button = self.buttons[1];
button.frame = CGRectMake(CONTENT_PADDING_LEFT + width + GAP, y, width, BUTTON_HEIGHT);
} else {

if (self.isNeedHorizonLayout) {
[self horizonLayout:y];
}
else {
[self verticalLayout:y];
}
}
}

}

-(void)verticalLayout:(CGFloat)y
{
for (NSUInteger i = 0; i < self.buttons.count; i++) {
UIButton *button = self.buttons[i];
button.frame = CGRectMake(CONTENT_PADDING_LEFT, y, self.containerView.bounds.size.width - CONTENT_PADDING_LEFT * 2, BUTTON_HEIGHT);
Expand All @@ -770,10 +784,27 @@ - (void)validateLayout
}
}
}
-(void)horizonLayout:(CGFloat)y
{
CGFloat btnWidth = (self.containerView.bounds.size.width-(self.buttons.count+1)*CONTENT_PADDING_LEFT)/self.buttons.count;
for (NSUInteger i = 0; i < self.buttons.count; i++) {
UIButton *button = self.buttons[i];
button.frame = CGRectMake(CONTENT_PADDING_LEFT+i*(btnWidth+CONTENT_PADDING_LEFT), y, btnWidth, BUTTON_HEIGHT);
}
}

- (CGFloat)preferredHeight
{
if (self.isNeedHorizonLayout) {
return [self preferredHorizonHeight];
}
else {
return [self preferredVeticalHeight];
}

}

-(CGFloat)preferredVeticalHeight
{
CGFloat height = CONTENT_PADDING_TOP;
if (self.title) {
Expand Down Expand Up @@ -802,6 +833,30 @@ - (CGFloat)preferredHeight
return height;
}

-(CGFloat)preferredHorizonHeight
{
CGFloat height = CONTENT_PADDING_TOP;
if (self.title) {
height += [self heightForTitleLabel];
}
if (self.message) {
if (height > CONTENT_PADDING_TOP) {
height += GAP;
}
height += [self heightForMessageLabel];
}
if (self.items.count > 0) {
if (height > CONTENT_PADDING_TOP) {
height += GAP;
}

height += BUTTON_HEIGHT;

}

height += CONTENT_PADDING_BOTTOM;
return height;
}
- (CGFloat)heightForTitleLabel
{
if (self.titleLabel) {
Expand Down