LTView.h
@interface LTView : UIView <UITextFieldDelegate>
@property (nonatomic, retain) UILabel *myLabel;
@property (nonatomic, retain) UITextField *myTextField;
@end
LTView.m
#import "LTView.h"
@implementation LTView
- (id) initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self createView];
}
return self;
}
- (void) createView{
self.myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 35)];
self.myLabel.text = @"Something:";
self.myLabel.backgroundColor = [UIColor whiteColor];
[self addSubview:self.myLabel];
[_myLabel release];
self.myTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 0, 220, 35)];
self.myTextField.placeholder = @"Please input something";
self.myTextField.borderStyle = UITextBorderStyleRoundedRect;
[self addSubview:self.myTextField];
[_myTextField release];
self.myTextField.delegate = self;
}
- (BOOL) textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
- (void)dealloc
{
[_myLabel release];
[_myTextField release];
[super dealloc];
}
@end