/*TextField改变*/
typedef void (^TXTextFieldDidChange)(TXCTextField * textField);
/*第一响应*/
typedef BOOL (^TXFirstResponder)(TXCTextField * textField);
/*描述Alignment*/
typedef NS_ENUM(NSInteger,TXPlaceholderAlignment){
TXPlaceholderAlignmentLeft = 0,//居左
TXPlaceholderAlignmentCenter = 1,//居中
TXPlaceholderAlignmentRight = 2,//居右
};
@interface TXCTextField : UITextField
/*描述字体*/
@property (nonatomic,strong)UIFont * placeholderFont;
/*描述颜色*/
@property (nonatomic,strong)UIColor * placeholderColor;
/*光标颜色*/
@property (nonatomic,strong)UIColor * cursorColor;
/*描述间距*/
@property (nonatomic,assign)CGFloat placeholderSpacing;
/*左侧文本填充宽度*/
@property (nonatomic,assign)CGFloat textFieldLeftPaddingWidth;
/*描述对齐方式*/
@property (nonatomic,assign)TXPlaceholderAlignment placeholderAlignment;
/*TextField改变*/
@property (nonatomic,copy)TXTextFieldDidChange textFieldDidChange;
/*第一响应*/
@property (nonatomic,copy)TXFirstResponder firstResponderHandler;
- (void)viewDidLoad {
[super viewDidLoad];
TXCTextField * textField=[[TXCTextField alloc]init];
textField.frame=CGRectMake(40, 64, self.view.frame.size.width-40*2, 30);
textField.layer.borderColor=[UIColor grayColor].CGColor;
textField.layer.borderWidth=1;
textField.layer.cornerRadius=15;
textField.layer.masksToBounds=YES;
textField.placeholder=@"描述";
//光标颜色
textField.cursorColor=[UIColor redColor];
//描述字体
textField.placeholderFont=[UIFont systemFontOfSize:13];
//描述对齐方式
textField.placeholderAlignment=TXPlaceholderAlignmentCenter;
//左侧文本填充宽度
textField.textFieldLeftPaddingWidth=10;
//TextField改变
textField.textFieldDidChange = ^(TXCTextField *textField) {
NSLog(@"text:%@",textField.text);
};
//第一响应
textField.firstResponderHandler = ^BOOL(TXCTextField *textField) {
NSLog(@"第一响应");
return YES;
};
[self.view addSubview:textField];
// Do any additional setup after loading the view, typically from a nib.
}