//
// LTView.m
// UI_Lesson_LTView
//
// Created by 李洪鹏 on 15/7/2.
// Copyright (c) 2015年 李洪鹏. All rights reserved.
//
#import "LTView.h"
@interface LTView() <UITextFieldDelegate>
@property (nonatomic, retain) UILabel *label;
@property (nonatomic, retain) UITextField *textField;
@end
@implementation LTView
//通过属性设置子控件的delegate
- (void)setDelegate:(id<UITextFieldDelegate>)delegate
{
self.textField.delegate = delegate;
}
- (instancetype)initWithFrame:(CGRect)frame label:(NSString *)label textFieldPlaceHolder:(NSString *)text
{
self = [super initWithFrame:frame];
if (self) {
//创建 label
self.label = [[[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width / 4, self.frame.size.height)] autorelease];
self.label.text = label;
[self addSubview:_label];
//创建 textField
self.textField = [[[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.label.frame), 0, self.frame.size.width / 4 * 3, self.frame.size.height)] autorelease];
self.textField.placeholder = text;
self.textField.borderStyle = UITextBorderStyleRoundedRect;
[self addSubview:_textField];
}
return self;
}
-(void)dealloc
{
[_label release];
[_textField release];
[super dealloc];
}
@end