Skip to content

Multiple UITextFields #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
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
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Bit Zeppelin .gitignore (iPhone projects)
# based on http://blog.illuminex.com/2009/10/better-sample-gitignore-file-for-xcode.html
# Mac OS X Finder and whatnot
.DS_Store

# Sparkle distribution Private Key (Don't check me in!)
dsa_priv.pem

# XCode (and ancestors) per-user config (very noisy, and not relevant)
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
*.xcworkspace/
xcuserdata/
.LSOverride

# Generated files
VersionX-revision.h

# build products
build/
*.[oa]

# Other source repository archive directories (protects when importing)
.hg
.svn
CVS

# automatic backup files
*~.nib
*.swp
*~
*(Autosaved).rtfd/
Backup[ ]of[ ]*.pages/
Backup[ ]of[ ]*.key/
Backup[ ]of[ ]*.numbers/

# others
*.pyc
144 changes: 97 additions & 47 deletions TSAlertView/TSAlertView.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,129 @@
//
// Created by Nick Hodapp aka Tom Swift on 1/19/11.
//


#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef enum
{
TSAlertViewButtonLayoutNormal,
TSAlertViewButtonLayoutStacked
TSAlertViewButtonLayoutNormal,
TSAlertViewButtonLayoutStacked
} TSAlertViewButtonLayout;

typedef enum
{
TSAlertViewStyleNormal,
TSAlertViewStyleInput,
TSAlertViewStyleNormal,
TSAlertViewStyleInput,
} TSAlertViewStyle;

@class TSAlertViewController;
@class TSAlertView;

@protocol TSAlertViewDelegate <NSObject>
@optional

// Called when a button is clicked. The view will be automatically dismissed after this call returns
- (void)alertView:(TSAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
@optional
// Called when a button is clicked. The view will be automatically dismissed
// after this call returns
- (void) alertView:(TSAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex;

// Called when we cancel a view (eg. the user clicks the Home button). This is not called when the user clicks the cancel button.
// Called when we cancel a view (eg. the user clicks the Home button). This is
// not called when the user clicks the cancel button.
// If not defined in the delegate, we simulate a click in the cancel button
- (void)alertViewCancel:(TSAlertView *)alertView;

- (void)willPresentAlertView:(TSAlertView *)alertView; // before animation and showing view
- (void)didPresentAlertView:(TSAlertView *)alertView; // after animation

- (void)alertView:(TSAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex; // before animation and hiding view
- (void)alertView:(TSAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; // after animation

// Before animation and showing view
- (void)willPresentAlertView:(TSAlertView *)alertView;
// After animation
- (void)didPresentAlertView:(TSAlertView *)alertView;

// Before animation and hiding view
- (void) alertView:(TSAlertView *)alertView
willDismissWithButtonIndex:(NSInteger)buttonIndex;
// After animation
- (void) alertView:(TSAlertView *)alertView
didDismissWithButtonIndex:(NSInteger)buttonIndex;
@end

@interface TSAlertView : UIView
@interface TSAlertView: UIView
{
UIImage* _backgroundImage;
UILabel* _titleLabel;
UILabel* _messageLabel;
UITextView* _messageTextView;
UIImageView* _messageTextViewMaskImageView;
UITextField* _inputTextField;
NSMutableArray* _buttons;
id<TSAlertViewDelegate> _delegate;
UIImage *_backgroundImage;
UILabel *_titleLabel;
UILabel *_messageLabel;
UITextView *_messageTextView;
UIImageView *_messageTextViewMaskImageView;
NSMutableArray *_buttons;
NSInteger _cancelButtonIndex;
TSAlertViewButtonLayout _buttonLayout;
NSInteger _firstOtherButtonIndex;
CGFloat _width;
CGFloat _maxHeight;
NSUInteger _shouldNotAdmitBlanks;
BOOL _usesMessageTextView;
TSAlertViewStyle _style;
// TSAlertView (TSCustomizableAlertView)
NSMutableArray *_textFields;
id _userInfo;
}
@property(nonatomic, copy) NSString *title;
@property(nonatomic, copy) NSString *message;
@property(nonatomic, assign) id<TSAlertViewDelegate> delegate;
@property(nonatomic) NSInteger cancelButtonIndex;
@property(nonatomic, readonly) NSInteger firstOtherButtonIndex;
@property(nonatomic, readonly) NSInteger numberOfButtons;
@property(nonatomic, readonly, getter=isVisible) BOOL visible;

@property(nonatomic, assign) TSAlertViewButtonLayout buttonLayout;
@property(nonatomic, assign) CGFloat width;
@property(nonatomic, assign) CGFloat maxHeight;
@property(nonatomic, assign) BOOL usesMessageTextView;
@property(nonatomic, retain) UIImage* backgroundImage;
@property(nonatomic, assign) TSAlertViewStyle style;
@property(nonatomic, readonly) UITextField* inputTextField;

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *message;
@property (nonatomic, assign) id<TSAlertViewDelegate> delegate;
@property (nonatomic, assign) NSInteger cancelButtonIndex;
@property (nonatomic, readonly) NSInteger firstOtherButtonIndex;
@property (nonatomic, readonly) NSInteger numberOfButtons;
@property (nonatomic, readonly, getter=isVisible) BOOL visible;
// shouldNotAdmitBlanks are flags, for each UITextField, from lest significant
// (i.e. [_textFields objectAtIndex:0]) to most significant bit
// (i.e. [_textFIelds objectAtIndex:n - 1]).
// By default shouldNotAdmitBlanks has its flags set for each initialzed
// UITextField
@property (nonatomic, assign) NSUInteger shouldNotAdmitBlanks;
@property (nonatomic, assign) BOOL usesMessageTextView;

@property (nonatomic, assign) TSAlertViewButtonLayout buttonLayout;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat maxHeight;
@property (nonatomic, retain) UIImage *backgroundImage;
@property (nonatomic, assign) TSAlertViewStyle style;
@property (nonatomic, readonly) UITextField *inputTextField;
@property (nonatomic, retain) id userInfo;

- (id)initWithTitle:(NSString *)title
message:(NSString *)message
delegate:(id)delegate
cancelButtonTitle:(NSString *)cancelButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ...;
- (NSInteger)addButtonWithTitle:(NSString *)title;
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex
animated:(BOOL)animated;
- (void)show;

@end




@interface TSAlertView (TSCustomizableAlertView)

// Returns the number of text fields added to the current instance
@property (nonatomic, readonly) NSInteger numberOfTextFields;
// Returns the first text field, identical to the message textFieldForIndex:
// with 0 as it argument, with the exception that firstTextField will return nil
// if there aren't any text fields, whereas textFieldForIndex: will throw an
// exception
@property (nonatomic, readonly) UITextField *firstTextField;

// Allows you to add a UITextField directly, without having TSAlertView to
// create it for you
- (void)addTextField:(UITextField *)textField;
// Creates and adds a UITextField, setting the placeholder value to the label
// parameter
- (UITextField *)addTextFieldWithLabel:(NSString *)label;
// Creates and adds a UITextField, setting the placeholder value to the label
// parameter, and the text value to the value parameter
- (UITextField *)addTextFieldWithLabel:(NSString *)label
value:(NSString *)value;
// Returns the UITextField instance at the specified index. Note: this method
- (UITextField *)textFieldAtIndex:(NSInteger)index;
@end
Loading