Label_TextField_自定義視圖

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
發佈了26 篇原創文章 · 獲贊 0 · 訪問量 5236
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章