您的位置:首页 > 移动开发 > IOS开发

iOS中收回键盘

2016-04-28 00:00 316 查看
让虚拟键盘在输入完后收回(点击屏幕空白处就收回了)

#import "ViewController.h"

@interface ViewController (){
UITextField *myTextField;
}

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

//新建一个UITextField
myTextField = [[UITextField alloc]initWithFrame:CGRectMake(0, 100, 300, 50)];

//设置边框
[myTextField setBorderStyle:UITextBorderStyleRoundedRect];

//设置键盘的样式
myTextField.keyboardType =  UIKeyboardTypeNamePhonePad;

[self.view addSubview:myTextField];

}

//让虚拟键盘在完成输入后收回(点空白处就收回了)
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

[myTextField resignFirstResponder];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: