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 @@ -75,6 +75,7 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView);
- (void)setDestructiveButtonImage:(UIImage *)destructiveButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

- (id)initWithTitle:(NSString *)title andMessage:(NSString *)message;
- (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type backgroundColor:(UIColor *)backgroundColor cornerRadius:(CGFloat)cornerRadius handler:(SIAlertViewHandler)handler;
- (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type handler:(SIAlertViewHandler)handler;

- (void)show;
Expand Down
21 changes: 21 additions & 0 deletions SIAlertView/SIAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ - (void)drawRect:(CGRect)rect
@interface SIAlertItem : NSObject

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) UIColor *backgroundColor;
@property (nonatomic, assign) CGFloat cornerRadius;
@property (nonatomic, assign) SIAlertViewButtonType type;
@property (nonatomic, copy) SIAlertViewHandler action;

Expand Down Expand Up @@ -350,12 +352,25 @@ - (void)setMessage:(NSString *)message

#pragma mark - Public

- (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type backgroundColor:(UIColor *)backgroundColor cornerRadius:(CGFloat)cornerRadius handler:(SIAlertViewHandler)handler
{
SIAlertItem *item = [[SIAlertItem alloc] init];
item.title = title;
item.type = type;
item.action = handler;
item.backgroundColor = backgroundColor;
item.cornerRadius = cornerRadius;
[self.items addObject:item];
}

- (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type handler:(SIAlertViewHandler)handler
{
SIAlertItem *item = [[SIAlertItem alloc] init];
item.title = title;
item.type = type;
item.action = handler;
item.backgroundColor = [UIColor clearColor];
item.cornerRadius = 0.0;
[self.items addObject:item];
}

Expand Down Expand Up @@ -754,12 +769,18 @@ - (void)validateLayout
CGFloat width = (self.containerView.bounds.size.width - CONTENT_PADDING_LEFT * 2 - GAP) * 0.5;
UIButton *button = self.buttons[0];
button.frame = CGRectMake(CONTENT_PADDING_LEFT, y, width, BUTTON_HEIGHT);
button.backgroundColor = ((SIAlertItem *)self.items[0]).backgroundColor;
button.layer.cornerRadius = ((SIAlertItem *)self.items[0]).cornerRadius;
button = self.buttons[1];
button.frame = CGRectMake(CONTENT_PADDING_LEFT + width + GAP, y, width, BUTTON_HEIGHT);
button.backgroundColor = ((SIAlertItem *)self.items[1]).backgroundColor;
button.layer.cornerRadius = ((SIAlertItem *)self.items[1]).cornerRadius;
} else {
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);
button.backgroundColor = ((SIAlertItem *)self.items[i]).backgroundColor;
button.layer.cornerRadius = ((SIAlertItem *)self.items[i]).cornerRadius;
if (self.buttons.count > 1) {
if (i == self.buttons.count - 1 && ((SIAlertItem *)self.items[i]).type == SIAlertViewButtonTypeCancel) {
CGRect rect = button.frame;
Expand Down