//
// ViewController.swift
// UITextField完成输入后关闭键盘的方法
//
// Created by 悦兑科技 on 15/1/19.
// Copyright (c) 2015年 BSY. All rights reserved.
//
import UIKit
class ViewController: UIViewController,UITextFieldDelegate {
var textF = UITextField()
override func viewDidLoad() {
super.viewDidLoad()
[self .addUITextField()];
}
func addUITextField(){
var text:UITextField = UITextField(frame: CGRectMake(30, 100, 260, 30))
text.layer.borderColor = UIColor .lightGrayColor().CGColor
text.layer.borderWidth = 2
self.view.addSubview(text)
text.delegate = self
self.textF = text
}
/**
第一种方法回退键盘
*/
// override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
// self.textF.resignFirstResponder()
// }
/**
第二种方法回退键盘
*/
func textFieldShouldReturn(textField: UITextField) -> Bool {
if(self.textF==textField){
textField.resignFirstResponder()
}
return true
}
}