//
// 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
}
}