#pragma mark -textfield
- (void)_inittextfield
{
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 180, 40)];
textField.tag = 200;
//背景颜色
textField.backgroundColor = [UIColor whiteColor];
//边框样式
// textField.borderStyle = UITextBorderStyleRoundedRect;
//输入的字体的大小
textField.font = [UIFont boldSystemFontOfSize:16];
//输入的字体的颜色
textField.textColor = [UIColor cyanColor];
//对齐方式
textField.textAlignment = NSTextAlignmentCenter;
//首字母自动大写
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
//输入框为空时提示的文字
textField.placeholder = @"请输入内容";
//开启清除按钮
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
//成为第一响应者
[textField becomeFirstResponder];
[self.window addSubview:textField];
//create button
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.backgroundColor = [UIColor greenColor];
button1.frame = CGRectMake(290, 100, 40, 40);
[button1 setTitle:@"^" forState:UIControlStateNormal];
//button1 click
[button1 addTarget:self action:@selector(button1Click) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:button1];
}
- (void)button1Click
{
UITextField *textField = (UITextField *)[self.window viewWithTag:200];
[textField resignFirstResponder];
}