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
2 changes: 2 additions & 0 deletions TSAlertView/TSAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ typedef enum
@property(nonatomic, readonly) NSInteger numberOfButtons;
@property(nonatomic, readonly, getter=isVisible) BOOL visible;

@property(nonatomic, assign) UIView *customSubview;

@property(nonatomic, assign) TSAlertViewButtonLayout buttonLayout;
@property(nonatomic, assign) CGFloat width;
@property(nonatomic, assign) CGFloat maxHeight;
Expand Down
55 changes: 45 additions & 10 deletions TSAlertView/TSAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ - (NSMutableArray*) buttons
return _buttons;
}


-(void)setCustomSubview:(UIView *)customSubview
{
_customSubview = customSubview;

[ self addSubview:customSubview ];
}


- (UILabel*) titleLabel
{
if ( _titleLabel == nil )
Expand All @@ -344,6 +353,8 @@ - (UILabel*) titleLabel
_titleLabel.textAlignment = UITextAlignmentCenter;
_titleLabel.lineBreakMode = UILineBreakModeWordWrap;
_titleLabel.numberOfLines = 0;

[self addSubview: _titleLabel];
}

return _titleLabel;
Expand All @@ -360,6 +371,8 @@ - (UILabel*) messageLabel
_messageLabel.textAlignment = UITextAlignmentCenter;
_messageLabel.lineBreakMode = UILineBreakModeWordWrap;
_messageLabel.numberOfLines = 0;

[self addSubview: _messageLabel];
}

return _messageLabel;
Expand All @@ -378,6 +391,8 @@ - (UITextView*) messageTextView
_messageTextView.bounces = YES;
_messageTextView.alwaysBounceVertical = YES;
_messageTextView.layer.cornerRadius = 5;

[self addSubview: _messageTextView];
}

return _messageTextView;
Expand All @@ -393,6 +408,8 @@ - (UIImageView*) messageTextViewMaskView
_messageTextViewMaskImageView.userInteractionEnabled = NO;
_messageTextViewMaskImageView.layer.masksToBounds = YES;
_messageTextViewMaskImageView.layer.cornerRadius = 6;

[self addSubview: _messageTextViewMaskImageView];
}
return _messageTextViewMaskImageView;
}
Expand All @@ -403,6 +420,8 @@ - (UITextField*) inputTextField
{
_inputTextField = [[UITextField alloc] init];
_inputTextField.borderStyle = UITextBorderStyleRoundedRect;

[self addSubview: _inputTextField];
}

return _inputTextField;
Expand Down Expand Up @@ -485,6 +504,8 @@ - (NSInteger) addButtonWithTitle: (NSString *) t

[self.buttons addObject: b];

[self addSubview: b];

[self setNeedsLayout];

return self.buttons.count-1;
Expand Down Expand Up @@ -554,6 +575,9 @@ - (void) show
{
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate:[NSDate date]];




TSAlertViewController* avc = [[[TSAlertViewController alloc] init] autorelease];
avc.view.backgroundColor = [UIColor clearColor];

Expand All @@ -575,6 +599,12 @@ - (void) show
[self sizeToFit];
self.center = CGPointMake( CGRectGetMidX( avc.view.bounds ), CGRectGetMidY( avc.view.bounds ) );;
self.frame = CGRectIntegral( self.frame );

if ( [self.delegate respondsToSelector: @selector(willPresentAlertView:)] )
{
[self.delegate willPresentAlertView: self ];
}

[self pulse];

if ( self.style == TSAlertViewStyleInput )
Expand All @@ -601,6 +631,11 @@ - (void) pulse
[UIView animateWithDuration:1.0/7.5
animations: ^{
self.transform = CGAffineTransformIdentity;

if ( [self.delegate respondsToSelector: @selector(didPresentAlertView:)] )
{
[self.delegate didPresentAlertView: self ];
}
}];
}];
}];
Expand Down Expand Up @@ -637,10 +672,11 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout
CGSize messageViewSize = [self messageLabelSize];
CGSize inputTextFieldSize = [self inputTextFieldSize];
CGSize buttonsAreaSize = stacked ? [self buttonsAreaSize_Stacked] : [self buttonsAreaSize_SideBySide];

CGSize customSubviewSize = ( self.customSubview ) ? self.customSubview.bounds.size : CGSizeZero;

CGFloat inputRowHeight = self.style == TSAlertViewStyleInput ? inputTextFieldSize.height + kTSAlertView_RowMargin : 0;

CGFloat totalHeight = kTSAlertView_TopMargin + titleLabelSize.height + kTSAlertView_RowMargin + messageViewSize.height + inputRowHeight + kTSAlertView_RowMargin + buttonsAreaSize.height + kTSAlertView_BottomMargin;
CGFloat totalHeight = kTSAlertView_TopMargin + titleLabelSize.height + kTSAlertView_RowMargin + messageViewSize.height + customSubviewSize.height + kTSAlertView_RowMargin + inputRowHeight + kTSAlertView_RowMargin + buttonsAreaSize.height + kTSAlertView_BottomMargin;

if ( totalHeight > self.maxHeight )
{
Expand All @@ -662,7 +698,6 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout
if ( self.title != nil )
{
self.titleLabel.frame = CGRectMake( kTSAlertView_LeftMargin, y, titleLabelSize.width, titleLabelSize.height );
[self addSubview: self.titleLabel];
y += titleLabelSize.height + kTSAlertView_RowMargin;
}

Expand All @@ -672,17 +707,14 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout
if ( self.usesMessageTextView )
{
self.messageTextView.frame = CGRectMake( kTSAlertView_LeftMargin, y, messageViewSize.width, messageViewSize.height );
[self addSubview: self.messageTextView];
y += messageViewSize.height + kTSAlertView_RowMargin;

UIImageView* maskImageView = [self messageTextViewMaskView];
maskImageView.frame = self.messageTextView.frame;
[self addSubview: maskImageView];
}
else
{
self.messageLabel.frame = CGRectMake( kTSAlertView_LeftMargin, y, messageViewSize.width, messageViewSize.height );
[self addSubview: self.messageLabel];
y += messageViewSize.height + kTSAlertView_RowMargin;
}
}
Expand All @@ -691,10 +723,16 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout
if ( self.style == TSAlertViewStyleInput )
{
self.inputTextField.frame = CGRectMake( kTSAlertView_LeftMargin, y, inputTextFieldSize.width, inputTextFieldSize.height );
[self addSubview: self.inputTextField];
y += inputTextFieldSize.height + kTSAlertView_RowMargin;
}

if( self.customSubview )
{
self.customSubview.frame = CGRectMake( kTSAlertView_LeftMargin, y, customSubviewSize.width, customSubviewSize.height );
y += customSubviewSize.height + kTSAlertView_RowMargin;
}


// buttons
CGFloat buttonHeight = [[self.buttons objectAtIndex:0] sizeThatFits: CGSizeZero].height;
if ( stacked )
Expand All @@ -703,7 +741,6 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout
for ( UIButton* b in self.buttons )
{
b.frame = CGRectMake( kTSAlertView_LeftMargin, y, buttonWidth, buttonHeight );
[self addSubview: b];
y += buttonHeight + kTSAlertView_RowMargin;
}
}
Expand All @@ -714,11 +751,9 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout
for ( UIButton* b in self.buttons )
{
b.frame = CGRectMake( x, y, buttonWidth, buttonHeight );
[self addSubview: b];
x += buttonWidth + kTSAlertView_ColumnMargin;
}
}

}

return CGSizeMake( self.width, totalHeight );
Expand Down