封装
//重写LTView继承自UIView的布局方法,来创建子视图,并添加子视图
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
//用参数中的frame(LTView视图整体的frame)来表示内部控件的frame
//LTView的宽和高
CGFloat totalWidth = frame.size.width;
CGFloat totalHeight = frame.size.height;
//lable的宽和高
CGFloat lableWidth = (totalWidth - 15) / 3;
CGFloat lableHeight = totalHeight - 4;
//textField的宽和高
CGFloat textFiledWidth = 2 * lableWidth;
CGFloat textFieldHeight = lableHeight;
_lable = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, lableWidth, lableHeight)];
// _lable.backgroundColor = [UIColor redColor];
[self addSubview:_lable];
_textField = [[UITextField alloc] initWithFrame:CGRectMake(10 + lableWidth, 2, textFiledWidth, textFieldHeight)];
// _textField.backgroundColor = [UIColor blueColor];
[self addSubview:_textField];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame text:(NSString *)text textColor:(UIColor *)textColor
font:(UIFont *)font borderStyle:(UITextBorderStyle)borderStyle placeholder:(NSString *)placeholder secureTextEbtry:(BOOL)secureTextEbtry keybordType:(UIKeyboardType)keybordType {
self = [self initWithFrame:frame];
if (self) {
self.lable.text = text;
self.lable.textColor = textColor;
self.lable.font = font;
self.textField.borderStyle = borderStyle;
self.textField.placeholder = placeholder;
self.textField.secureTextEntry = secureTextEbtry;
self.textField.keyboardType = keybordType;
}
return self;
}