#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 150,100)];
textField.backgroundColor = [UIColor cyanColor];
[self.view addSubview:textField];
textField.layer.borderWidth = 1;
[textField setBorderStyle:UITextBorderStyleRoundedRect];
[textField setPlaceholder:@"请输入内容"];
[textField setSecureTextEntry:YES];
textField.delegate = self;
textField.clearsOnBeginEditing = YES;
textField.font = [UIFont systemFontOfSize:60];
textField.minimumFontSize = 20;
textField.adjustsFontSizeToFitWidth = YES;
[textField setClearButtonMode:UITextFieldViewModeWhileEditing];
[textField setKeyboardAppearance:UIKeyboardAppearanceDefault];
self.view.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]init];
[self.view addGestureRecognizer:tap];
[tap addTarget:self action:@selector(tapClick)];
}
#pragma mark - UITextField协议方法
-(void)textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"已经进入编辑");
}
-(void)textFieldDidEndEditing:(UITextField *)textField {
NSLog(@"已经结束编辑");
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
NSLog(@"是否允许再次编辑");
return YES;
}
-(BOOL)textFieldShouldClear:(UITextField *)textField {
NSLog(@"是否允许清空");
return YES;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSLog(@"是否结束编辑");
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@"是否使用return");
[textField resignFirstResponder];
return YES;
}
-(void)tapClick {
[self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end