diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac8f968 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so +*.pyc + +# Logs and databases # +###################### +*.log + +# OS generated files # +###################### +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db diff --git a/Demo/Classes/TSAVDemoAppDelegate.m b/Demo/Classes/TSAVDemoAppDelegate.m index 7f386b6..b39dab0 100644 --- a/Demo/Classes/TSAVDemoAppDelegate.m +++ b/Demo/Classes/TSAVDemoAppDelegate.m @@ -17,8 +17,8 @@ @implementation TSAVDemoAppDelegate #pragma mark - #pragma mark Application lifecycle -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. // Add the view controller's view to the window and display. @@ -39,7 +39,7 @@ - (void)applicationWillResignActive:(UIApplication *)application { - (void)applicationDidEnterBackground:(UIApplication *)application { /* - Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. If your application supports background execution, called instead of applicationWillTerminate: when the user quits. */ } diff --git a/Demo/Classes/TSAVDemoViewController.h b/Demo/Classes/TSAVDemoViewController.h index 731f099..0cdd4ea 100644 --- a/Demo/Classes/TSAVDemoViewController.h +++ b/Demo/Classes/TSAVDemoViewController.h @@ -11,11 +11,11 @@ @interface TSAVDemoViewController : UIViewController { IBOutlet UITextField* _titleTextField; - + IBOutlet UITextView* _messageTextView; - + IBOutlet UITextField* _widthTextField; - + IBOutlet UITextField* _maxHeightTextField; IBOutlet UITextField* _buttonCountTextField; @@ -24,7 +24,7 @@ IBOutlet UISwitch* _stackedSwitch; IBOutlet UISwitch* _usesTextViewSwitch; - + IBOutlet UISwitch* _hasInputFieldSwitch; } diff --git a/Demo/Classes/TSAVDemoViewController.m b/Demo/Classes/TSAVDemoViewController.m index 21f852d..95011f5 100644 --- a/Demo/Classes/TSAVDemoViewController.m +++ b/Demo/Classes/TSAVDemoViewController.m @@ -40,26 +40,26 @@ - (void) onAddMore:(id)sender { } -- (void) onShow:(id)sender +- (void) onShow:(id)sender { [_messageTextView resignFirstResponder]; [_titleTextField resignFirstResponder]; [_widthTextField resignFirstResponder]; [_maxHeightTextField resignFirstResponder]; - + TSAlertView* av = [[[TSAlertView alloc] init] autorelease]; av.title = _titleTextField.text; av.message = _messageTextView.text; - + for ( int i = 0 ; i < [_buttonCountTextField.text intValue] ; i++ ) { [av addButtonWithTitle: [NSString stringWithFormat: @"Button %d", i]]; } - + av.style = _hasInputFieldSwitch.on ? TSAlertViewStyleInput : TSAlertViewStyleNormal; av.buttonLayout = _stackedSwitch.on ? TSAlertViewButtonLayoutStacked : TSAlertViewButtonLayoutNormal; av.usesMessageTextView = _usesTextViewSwitch.on; - + av.width = [_widthTextField.text floatValue]; av.maxHeight = [_maxHeightTextField.text floatValue]; @@ -75,7 +75,7 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; - + // Release any cached data, images, etc. that aren't in use. } diff --git a/Demo/main.m b/Demo/main.m index c848107..a422a7f 100644 --- a/Demo/main.m +++ b/Demo/main.m @@ -8,7 +8,7 @@ #import int main(int argc, char *argv[]) { - + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; diff --git a/Source Code License.rtf b/Source Code License.rtf index 9c09b44..e3d7c32 100755 --- a/Source Code License.rtf +++ b/Source Code License.rtf @@ -18,48 +18,48 @@ Thanks for downloading some of our source code!\ \ This is the license agreement for the source code which this document accompanies (don\'92t worry: you\'92re allowed to use it in your own products, commercial or otherwise).\ \ -The full license text is further down this page, and you should only use the source code if you agree to the terms in that text. For convenience, though, we\'92ve put together a human-readable +The full license text is further down this page, and you should only use the source code if you agree to the terms in that text. For convenience, though, we\'92ve put together a human-readable \b non-authoritative \b0 interpretation of the license which will hopefully answer any questions you have.\ \ \ \b \cf3 Green -\b0 \cf2 text shows +\b0 \cf2 text shows \b \cf3 what you can do with the code \b0 \cf2 .\ \b \cf4 Red -\b0 \cf2 text means +\b0 \cf2 text means \b \cf4 restrictions you must abide by \b0 \cf2 .\ \ Basically, the license says that:\ \ \pard\tx220\tx720\pardeftab720\li720\fi-720\ql\qnatural -\ls1\ilvl0\cf2 {\listtext 1. }You can +\ls1\ilvl0\cf2 {\listtext 1. }You can \b \cf3 use the code in your own products, including commercial and/or closed-source products \b0 \cf2 .\ -{\listtext 2. }You can +{\listtext 2. }You can \b \cf3 modify the code -\b0 \cf0 as you wish\cf2 , and +\b0 \cf0 as you wish\cf2 , and \b \cf3 use the modified code in your products \b0 \cf2 .\ -{\listtext 3. }You can +{\listtext 3. }You can \b \cf3 redistribute the original, unmodified code -\b0 \cf2 , but you +\b0 \cf2 , but you \b \cf4 have to include the full license text below \b0 \cf2 .\ -{\listtext 4. }You can +{\listtext 4. }You can \b \cf3 redistribute the modified code \b0 \cf2 as you wish ( \b \cf4 without the full license text below \b0 \cf2 ).\ -{\listtext 5. }In all cases, you +{\listtext 5. }In all cases, you \b \cf4 must include a credit mentioning Nick Hodapp \b0 \cf2 as the original author of the source.\ {\listtext 6. }Nick Hodapp is \cf0 not liable for anything you do with the code\cf2 , no matter what. So be sensible.\ -{\listtext 7. }You +{\listtext 7. }You \b \cf4 can\'92t use the name Nick Hodapp, the name CoDeveloper LLC, the CoDeveloper logo or any other related marks to promote your products \b0 \cf2 based on the code.\ {\listtext 8. }If you agree to all of that, go ahead and use the source. Otherwise, don\'92t!\ diff --git a/TSAlertView/TSAlertView.h b/TSAlertView/TSAlertView.h index dfdc97c..76ca890 100644 --- a/TSAlertView/TSAlertView.h +++ b/TSAlertView/TSAlertView.h @@ -7,18 +7,18 @@ #import -typedef enum +typedef enum { TSAlertViewButtonLayoutNormal, TSAlertViewButtonLayoutStacked - + } TSAlertViewButtonLayout; typedef enum { TSAlertViewStyleNormal, TSAlertViewStyleInput, - + } TSAlertViewStyle; @class TSAlertViewController; diff --git a/TSAlertView/TSAlertView.m b/TSAlertView/TSAlertView.m index e83fe74..84b4b41 100644 --- a/TSAlertView/TSAlertView.m +++ b/TSAlertView/TSAlertView.m @@ -32,33 +32,33 @@ - (void) resignKeyWindow - (void) drawRect: (CGRect) rect { // render the radial gradient behind the alertview - + CGFloat width = self.frame.size.width; CGFloat height = self.frame.size.height; CGFloat locations[3] = { 0.0, 0.5, 1.0 }; CGFloat components[12] = { 1, 1, 1, 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.7 }; - + CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); CGGradientRef backgroundGradient = CGGradientCreateWithColorComponents(colorspace, components, locations, 3); CGColorSpaceRelease(colorspace); - - CGContextDrawRadialGradient(UIGraphicsGetCurrentContext(), - backgroundGradient, + + CGContextDrawRadialGradient(UIGraphicsGetCurrentContext(), + backgroundGradient, CGPointMake(width/2, height/2), 0, CGPointMake(width/2, height/2), width, 0); - + CGGradientRelease(backgroundGradient); } - (void) dealloc { self.oldKeyWindow = nil; - + NSLog( @"TSAlertView: TSAlertOverlayWindow dealloc" ); - + [super dealloc]; } @@ -96,7 +96,7 @@ - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interf if (!av || ![av isKindOfClass:[TSAlertView class]]) return; // resize the alertview if it wants to make use of any extra space (or needs to contract) - [UIView animateWithDuration:duration + [UIView animateWithDuration:duration animations:^{ [av sizeToFit]; av.center = CGPointMake( CGRectGetMidX( self.view.bounds ), CGRectGetMidY( self.view.bounds ) );; @@ -131,7 +131,7 @@ @implementation TSAlertView const CGFloat kTSAlertView_RowMargin = 5.0; const CGFloat kTSAlertView_ColumnMargin = 10.0; -- (id) init +- (id) init { if ( ( self = [super init] ) ) { @@ -145,7 +145,7 @@ - (id) initWithFrame:(CGRect)frame if ( ( self = [super initWithFrame: frame] ) ) { [self TSAlertView_commonInit]; - + if ( !CGRectIsEmpty( frame ) ) { width = frame.size.width; @@ -162,36 +162,36 @@ - (id) initWithTitle: (NSString *) t message: (NSString *) m delegate: (id) d ca self.title = t; self.message = m; self.delegate = d; - + if ( nil != cancelButtonTitle ) { [self addButtonWithTitle: cancelButtonTitle ]; self.cancelButtonIndex = 0; } - + if ( nil != otherButtonTitles ) { firstOtherButtonIndex = [self.buttons count]; [self addButtonWithTitle: otherButtonTitles ]; - + va_list args; va_start(args, otherButtonTitles); - + id arg; - while ( nil != ( arg = va_arg( args, id ) ) ) + while ( nil != ( arg = va_arg( args, id ) ) ) { if ( ![arg isKindOfClass: [NSString class] ] ) return nil; - + [self addButtonWithTitle: (NSString*)arg ]; } } } - + return self; } -- (CGSize) sizeThatFits: (CGSize) unused +- (CGSize) sizeThatFits: (CGSize) unused { CGSize s = [self recalcSizeAndLayout: NO]; return s; @@ -207,7 +207,7 @@ - (void) drawRect:(CGRect)rect [self.backgroundImage drawInRect: rect]; } -- (void)dealloc +- (void)dealloc { [_backgroundImage release]; [_buttons release]; @@ -215,11 +215,11 @@ - (void)dealloc [_messageLabel release]; [_messageTextView release]; [_messageTextViewMaskImageView release]; - + [[NSNotificationCenter defaultCenter] removeObserver: self ]; - + NSLog( @"TSAlertView: TSAlertOverlayWindow dealloc" ); - + [super dealloc]; } @@ -227,8 +227,8 @@ - (void)dealloc - (void) TSAlertView_commonInit { self.backgroundColor = [UIColor clearColor]; - self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; - + self.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; + // defaults: style = TSAlertViewStyleNormal; self.width = 0; // set to default @@ -242,7 +242,7 @@ - (void) setWidth:(CGFloat) w { if ( w <= 0 ) w = 284; - + width = MAX( w, self.backgroundImage.size.width ); } @@ -250,9 +250,9 @@ - (CGFloat) width { if ( nil == self.superview ) return width; - + CGFloat maxWidth = self.superview.bounds.size.width - 20; - + return MIN( width, maxWidth ); } @@ -260,7 +260,7 @@ - (void) setMaxHeight:(CGFloat) h { if ( h <= 0 ) h = 358; - + maxHeight = MAX( h, self.backgroundImage.size.height ); } @@ -268,7 +268,7 @@ - (CGFloat) maxHeight { if ( nil == self.superview ) return maxHeight; - + return MIN( maxHeight, self.superview.bounds.size.height - 20 ); } @@ -277,7 +277,7 @@ - (void) setStyle:(TSAlertViewStyle)newStyle if ( style != newStyle ) { style = newStyle; - + if ( style == TSAlertViewStyleInput ) { // need to watch for keyboard @@ -292,21 +292,21 @@ - (void) onKeyboardWillShow: (NSNotification*) note NSValue* v = [note.userInfo objectForKey: UIKeyboardFrameEndUserInfoKey]; CGRect kbframe = [v CGRectValue]; kbframe = [self.superview convertRect: kbframe fromView: nil]; - + if ( CGRectIntersectsRect( self.frame, kbframe) ) { CGPoint c = self.center; - + if ( self.frame.size.height > kbframe.origin.y - 20 ) { self.maxHeight = kbframe.origin.y - 20; [self sizeToFit]; [self layoutSubviews]; } - + c.y = kbframe.origin.y / 2; - - [UIView animateWithDuration: 0.2 + + [UIView animateWithDuration: 0.2 animations: ^{ self.center = c; self.frame = CGRectIntegral(self.frame); @@ -316,7 +316,7 @@ - (void) onKeyboardWillShow: (NSNotification*) note - (void) onKeyboardWillHide: (NSNotification*) note { - [UIView animateWithDuration: 0.2 + [UIView animateWithDuration: 0.2 animations: ^{ self.center = CGPointMake( CGRectGetMidX( self.superview.bounds ), CGRectGetMidY( self.superview.bounds )); self.frame = CGRectIntegral(self.frame); @@ -329,7 +329,7 @@ - (NSMutableArray*) buttons { _buttons = [[NSMutableArray arrayWithCapacity:4] retain]; } - + return _buttons; } @@ -345,7 +345,7 @@ - (UILabel*) titleLabel _titleLabel.lineBreakMode = UILineBreakModeWordWrap; _titleLabel.numberOfLines = 0; } - + return _titleLabel; } @@ -361,7 +361,7 @@ - (UILabel*) messageLabel _messageLabel.lineBreakMode = UILineBreakModeWordWrap; _messageLabel.numberOfLines = 0; } - + return _messageLabel; } @@ -379,7 +379,7 @@ - (UITextView*) messageTextView _messageTextView.alwaysBounceVertical = YES; _messageTextView.layer.cornerRadius = 5; } - + return _messageTextView; } @@ -388,7 +388,7 @@ - (UIImageView*) messageTextViewMaskView if ( _messageTextViewMaskImageView == nil ) { UIImage* shadowImage = [[UIImage imageNamed:@"TSAlertViewMessageListViewShadow.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:7]; - + _messageTextViewMaskImageView = [[UIImageView alloc] initWithImage: shadowImage]; _messageTextViewMaskImageView.userInteractionEnabled = NO; _messageTextViewMaskImageView.layer.masksToBounds = YES; @@ -404,7 +404,7 @@ - (UITextField*) inputTextField _inputTextField = [[UITextField alloc] init]; _inputTextField.borderStyle = UITextBorderStyleRoundedRect; } - + return _inputTextField; } @@ -414,7 +414,7 @@ - (UIImage*) backgroundImage { self.backgroundImage = [[UIImage imageNamed: @"TSAlertViewBackground.png"] stretchableImageWithLeftCapWidth: 15 topCapHeight: 30]; } - + return _backgroundImage; } @@ -423,7 +423,7 @@ - (void) setTitle:(NSString *)t self.titleLabel.text = t; } -- (NSString*) title +- (NSString*) title { return self.titleLabel.text; } @@ -434,7 +434,7 @@ - (void) setMessage:(NSString *)t self.messageTextView.text = t; } -- (NSString*) message +- (NSString*) message { return self.messageLabel.text; } @@ -449,15 +449,15 @@ - (void) setCancelButtonIndex:(NSInteger)buttonIndex // avoid a NSRange exception if ( buttonIndex < 0 || buttonIndex >= [self.buttons count] ) return; - + cancelButtonIndex = buttonIndex; - + UIButton* b = [self.buttons objectAtIndex: buttonIndex]; - + UIImage* buttonBgNormal = [UIImage imageNamed: @"TSAlertViewCancelButtonBackground.png"]; buttonBgNormal = [buttonBgNormal stretchableImageWithLeftCapWidth: buttonBgNormal.size.width / 2.0 topCapHeight: buttonBgNormal.size.height / 2.0]; [b setBackgroundImage: buttonBgNormal forState: UIControlStateNormal]; - + UIImage* buttonBgPressed = [UIImage imageNamed: @"TSAlertViewButtonBackground_Highlighted.png"]; buttonBgPressed = [buttonBgPressed stretchableImageWithLeftCapWidth: buttonBgPressed.size.width / 2.0 topCapHeight: buttonBgPressed.size.height / 2.0]; [b setBackgroundImage: buttonBgPressed forState: UIControlStateHighlighted]; @@ -472,21 +472,21 @@ - (NSInteger) addButtonWithTitle: (NSString *) t { UIButton* b = [UIButton buttonWithType: UIButtonTypeCustom]; [b setTitle: t forState: UIControlStateNormal]; - + UIImage* buttonBgNormal = [UIImage imageNamed: @"TSAlertViewButtonBackground.png"]; buttonBgNormal = [buttonBgNormal stretchableImageWithLeftCapWidth: buttonBgNormal.size.width / 2.0 topCapHeight: buttonBgNormal.size.height / 2.0]; [b setBackgroundImage: buttonBgNormal forState: UIControlStateNormal]; - + UIImage* buttonBgPressed = [UIImage imageNamed: @"TSAlertViewButtonBackground_Highlighted.png"]; buttonBgPressed = [buttonBgPressed stretchableImageWithLeftCapWidth: buttonBgPressed.size.width / 2.0 topCapHeight: buttonBgPressed.size.height / 2.0]; [b setBackgroundImage: buttonBgPressed forState: UIControlStateHighlighted]; - + [b addTarget: self action: @selector(onButtonPress:) forControlEvents: UIControlEventTouchUpInside]; - + [self.buttons addObject: b]; - + [self setNeedsLayout]; - + return self.buttons.count-1; } @@ -495,9 +495,9 @@ - (NSString *) buttonTitleAtIndex:(NSInteger)buttonIndex // avoid a NSRange exception if ( buttonIndex < 0 || buttonIndex >= [self.buttons count] ) return nil; - + UIButton* b = [self.buttons objectAtIndex: buttonIndex]; - + return [b titleForState: UIControlStateNormal]; } @@ -507,18 +507,18 @@ - (void) dismissWithClickedButtonIndex: (NSInteger)buttonIndex animated: (BOOL) { [self.inputTextField resignFirstResponder]; } - + if ( [self.delegate respondsToSelector: @selector(alertView:willDismissWithButtonIndex:)] ) { [self.delegate alertView: self willDismissWithButtonIndex: buttonIndex ]; } - + if ( animated ) { self.window.backgroundColor = [UIColor clearColor]; self.window.alpha = 1; - - [UIView animateWithDuration: 0.2 + + [UIView animateWithDuration: 0.2 animations: ^{ [self.window resignKeyWindow]; self.window.alpha = 0; @@ -526,13 +526,13 @@ - (void) dismissWithClickedButtonIndex: (NSInteger)buttonIndex animated: (BOOL) completion: ^(BOOL finished) { [self releaseWindow: buttonIndex]; }]; - + [UIView commitAnimations]; } else { [self.window resignKeyWindow]; - + [self releaseWindow: buttonIndex]; } } @@ -543,32 +543,32 @@ - (void) releaseWindow: (int) buttonIndex { [self.delegate alertView: self didDismissWithButtonIndex: buttonIndex ]; } - + // the one place we release the window we allocated in "show" // this will propogate releases to us (TSAlertView), and our TSAlertViewController - + [self.window release]; } - (void) show { [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate:[NSDate date]]; - + TSAlertViewController* avc = [[[TSAlertViewController alloc] init] autorelease]; avc.view.backgroundColor = [UIColor clearColor]; - + // $important - the window is released only when the user clicks an alert view button TSAlertOverlayWindow* ow = [[TSAlertOverlayWindow alloc] initWithFrame: [UIScreen mainScreen].bounds]; ow.alpha = 0.0; ow.backgroundColor = [UIColor clearColor]; ow.rootViewController = avc; [ow makeKeyAndVisible]; - + // fade in the window [UIView animateWithDuration: 0.2 animations: ^{ ow.alpha = 1; }]; - + // add and pulse the alertview // add the alertview [avc.view addSubview: self]; @@ -576,7 +576,7 @@ - (void) show self.center = CGPointMake( CGRectGetMidX( avc.view.bounds ), CGRectGetMidY( avc.view.bounds ) );; self.frame = CGRectIntegral( self.frame ); [self pulse]; - + if ( self.style == TSAlertViewStyleInput ) { [self layoutSubviews]; @@ -588,7 +588,7 @@ - (void) pulse { // pulse animation thanks to: http://delackner.com/blog/2009/12/mimicking-uialertviews-animated-transition/ self.transform = CGAffineTransformMakeScale(0.6, 0.6); - [UIView animateWithDuration: 0.2 + [UIView animateWithDuration: 0.2 animations: ^{ self.transform = CGAffineTransformMakeScale(1.1, 1.1); } @@ -604,57 +604,57 @@ - (void) pulse }]; }]; }]; - + } - (void) onButtonPress: (id) sender { int buttonIndex = [_buttons indexOfObjectIdenticalTo: sender]; - + if ( [self.delegate respondsToSelector: @selector(alertView:clickedButtonAtIndex:)] ) { [self.delegate alertView: self clickedButtonAtIndex: buttonIndex ]; } - + if ( buttonIndex == self.cancelButtonIndex ) { if ( [self.delegate respondsToSelector: @selector(alertViewCancel:)] ) { [self.delegate alertViewCancel: self ]; - } + } } - + [self dismissWithClickedButtonIndex: buttonIndex animated: YES]; } - (CGSize) recalcSizeAndLayout: (BOOL) layout { BOOL stacked = !(self.buttonLayout == TSAlertViewButtonLayoutNormal && [self.buttons count] == 2 ); - + CGFloat maxWidth = self.width - (kTSAlertView_LeftMargin * 2); - + CGSize titleLabelSize = [self titleLabelSize]; CGSize messageViewSize = [self messageLabelSize]; CGSize inputTextFieldSize = [self inputTextFieldSize]; CGSize buttonsAreaSize = stacked ? [self buttonsAreaSize_Stacked] : [self buttonsAreaSize_SideBySide]; - + 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; - + if ( totalHeight > self.maxHeight ) { // too tall - we'll condense by using a textView (with scrolling) for the message - + totalHeight -= messageViewSize.height; //$$what if it's still too tall? messageViewSize.height = self.maxHeight - totalHeight; - + totalHeight = self.maxHeight; - + self.usesMessageTextView = YES; } - + if ( layout ) { // title @@ -665,7 +665,7 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout [self addSubview: self.titleLabel]; y += titleLabelSize.height + kTSAlertView_RowMargin; } - + // message if ( self.message != nil ) { @@ -674,7 +674,7 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout 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]; @@ -686,7 +686,7 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout y += messageViewSize.height + kTSAlertView_RowMargin; } } - + // input if ( self.style == TSAlertViewStyleInput ) { @@ -694,7 +694,7 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout [self addSubview: self.inputTextField]; y += inputTextFieldSize.height + kTSAlertView_RowMargin; } - + // buttons CGFloat buttonHeight = [[self.buttons objectAtIndex:0] sizeThatFits: CGSizeZero].height; if ( stacked ) @@ -718,9 +718,9 @@ - (CGSize) recalcSizeAndLayout: (BOOL) layout x += buttonWidth + kTSAlertView_ColumnMargin; } } - + } - + return CGSizeMake( self.width, totalHeight ); } @@ -730,7 +730,7 @@ - (CGSize) titleLabelSize CGSize s = [self.titleLabel.text sizeWithFont: self.titleLabel.font constrainedToSize: CGSizeMake(maxWidth, 1000) lineBreakMode: self.titleLabel.lineBreakMode]; if ( s.width < maxWidth ) s.width = maxWidth; - + return s; } @@ -740,7 +740,7 @@ - (CGSize) messageLabelSize CGSize s = [self.messageLabel.text sizeWithFont: self.messageLabel.font constrainedToSize: CGSizeMake(maxWidth, 1000) lineBreakMode: self.messageLabel.lineBreakMode]; if ( s.width < maxWidth ) s.width = maxWidth; - + return s; } @@ -748,22 +748,22 @@ - (CGSize) inputTextFieldSize { if ( self.style == TSAlertViewStyleNormal) return CGSizeZero; - + CGFloat maxWidth = self.width - (kTSAlertView_LeftMargin * 2); - + CGSize s = [self.inputTextField sizeThatFits: CGSizeZero]; - + return CGSizeMake( maxWidth, s.height ); } - (CGSize) buttonsAreaSize_SideBySide { CGFloat maxWidth = self.width - (kTSAlertView_LeftMargin * 2); - + CGSize bs = [[self.buttons objectAtIndex:0] sizeThatFits: CGSizeZero]; - + bs.width = maxWidth; - + return bs; } @@ -771,13 +771,13 @@ - (CGSize) buttonsAreaSize_Stacked { CGFloat maxWidth = self.width - (kTSAlertView_LeftMargin * 2); int buttonCount = [self.buttons count]; - + CGSize bs = [[self.buttons objectAtIndex:0] sizeThatFits: CGSizeZero]; - + bs.width = maxWidth; - + bs.height = (bs.height * buttonCount) + (kTSAlertView_RowMargin * (buttonCount-1)); - + return bs; }