标签:des style color io 文件 ar div cti
源代码(.m文件)
#import "TLView.h"
//本类的延展
@interface TLView ()
{
UILabel *_desLabel; //左边的lable
UITextField *_textField;//右边的lable
}
@end
@implementation TLView
//改写父类的初始化方法,处理相同的性能
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
CGFloat width = frame.size.width;
CGFloat height = frame.size.height;
//UIlabel
_desLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0.3 * width, height)];
_desLabel.font = [UIFont systemFontOfSize:18];
_desLabel.textAlignment = NSTextAlignmentRight;
// _desLabel.backgroundColor = [UIColor lightGrayColor];
[self addSubview:_desLabel];
[_desLabel release];
//UITextfield
_textField = [[UITextField alloc] initWithFrame:CGRectMake(0.4 * width, 0 , 0.6 * width , height)];
_textField.borderStyle = UITextBorderStyleRoundedRect;
// _textField.backgroundColor = [UIColor lightGrayColor];
_textField.autocorrectionType = UITextAutocorrectionTypeNo;
[self addSubview:_textField];
[_textField release];
}
return self;
}
//改写初始化方法,处理不同的部分
- (id)initWithFrame:(CGRect)frame labelText:(NSString *)labelText placeholder:(NSString *)placeholder textFieldText:(NSString *)textFieldText{
self = [self initWithFrame:frame];
if (self) {
//initialization code here..
_desLabel.text = labelText; //
_textField.placeholder = placeholder;
_textField.text = textFieldText;
}
return self;
}
//填写各种方法,处理不同的部分
//1,是否采用安全模式
- (void)setSecureEntry:(BOOL)secureEntry{
_textField.secureTextEntry = secureEntry;
}
//2,设置键盘类型;
- (void)setKeyBoardType:(UIKeyboardType)keyBoardType{
_textField.keyboardType = keyBoardType;
}
//3,设置textField代理
- (void)setDelegate:(id<UITextFieldDelegate>)delegate{
_textField.delegate = delegate;
}
//4,获取输入框中的文字
- (NSString *)text{
return _textField.text;
}
@end
如何封装UILable 输入框 和UIField 显示框 同时创建对象(经典),布布扣,bubuko.com
如何封装UILable 输入框 和UIField 显示框 同时创建对象(经典)
标签:des style color io 文件 ar div cti
原文地址:http://blog.csdn.net/chenhongyi_1992/article/details/38727595