2014년 10월 29일 수요일
UIAlertView에 UITextField 추가( UIAlertView Customize, IOS )
구글에서 찾은건데 약간 버그가 있어서, 수정했다.
//AlertPrompt.h
#import <Foundation/Foundation.h>
@interface AlertPrompt : UIAlertView
{
UITextField *textField;
}
@property (nonatomic, retain) UITextField *textField;
@property (readonly) NSString *enteredText;
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okButtonTitle;
@end
//AlertPrompt.mm
#import "AlertPrompt.h"
@implementation AlertPrompt
@synthesize textField;
@synthesize enteredText;
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle
{
NSString *msg = [ NSString stringWithFormat:@"\n%@", message ];
if (self = [super initWithTitle:title message:msg delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil])
{
UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 40.0, 260.0, 25.0)];
[theTextField setBackgroundColor:[UIColor whiteColor]];
[self addSubview:theTextField];
self.textField = theTextField;
[theTextField release];
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 130.0);
[self setTransform:translate];
}
return self;
}
- (void)show
{
[textField becomeFirstResponder];
[super show];
}
- (NSString *)enteredText
{
return textField.text;
}
- (void)dealloc
{
[textField release];
[super dealloc];
}
@end
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기