//
// ViewController.swift
// UITextField键盘类型
//
// Created by mac on 15/4/19.
// Copyright (c) 2015年 mac. All rights reserved.
//
import UIKit
class ViewController: UIViewController,UITextFieldDelegate{
var text = UITextField()
var pwdtext = UITextField()
override func viewDidLoad() {
super.viewDidLoad()
// Default // Default type for the current input method.
// case ASCIICapable // Displays a keyboard which can enter ASCII characters,non-ASCII keyboards remain active
// case NumbersAndPunctuation // Numbers and assorted punctuation.
// case URL // A type optimized for URL entry (shows . / .com prominently).
// case NumberPad // A number pad (0-9). Suitable for PIN entry.
// case PhonePad // A phone pad (1-9,*,#,with letters under the numbers).
// case NamePhonePad // A type optimized for entering a person's name or phone number.
// case EmailAddress // A type optimized for multiple email address entry (shows space @ . prominently).
// case DecimalPad // A number pad with a decimal point.
// case Twitter // A type optimized for twitter text entry (easy access to @ #)
// case WebSearch // A default keyboard type with URL-oriented addition (shows space . prominently).
// 设置背景图片
var imageview = UIImageView(frame: self.view.bounds)
let image = UIImage(named: "1.png")
imageview.image = image
self.view.addSubview(imageview)
// 定义用户名输入框
var text = UITextField(frame: CGRectMake(30,100,UIScreen.mainScreen().bounds.size.width-60,30))
text.delegate = self
text.keyboardType = UIKeyboardType.Default
text.layer.borderWidth = 0.5
text.layer.borderColor = UIColor.lightGrayColor().CGColor
text.placeholder = "请输入用户名"
text.clearButtonMode = UITextFieldviewmode.Always
self.view.addSubview(text)
text.returnKeyType = UIReturnKeyType.Done
self.text = text
let lab = UILabel(frame: CGRectMake(0,70,text.bounds.size.height))
lab.text = "用户名:"
text.leftView = lab
// lab.font = UIFont.systemFontOfSize(17.0)
text.leftviewmode = UITextFieldviewmode.Always
var pwdtext = UITextField(frame: CGRectMake(30,150,30))
pwdtext.delegate = self
pwdtext.keyboardType = UIKeyboardType.NumberPad
pwdtext.layer.borderWidth = 0.5
pwdtext.layer.borderColor = UIColor.lightGrayColor().CGColor
pwdtext.placeholder = "请输入文字"
pwdtext.clearButtonMode = UITextFieldviewmode.WhileEditing
self.view.addSubview(pwdtext)
pwdtext.returnKeyType = UIReturnKeyType.Done
self.pwdtext = pwdtext
let pwd = UILabel(frame: CGRectMake(0,text.bounds.size.height))
pwd.text = "验证码:"
pwdtext.leftView = pwd
pwd.font = UIFont.systemFontOfSize(17.0)
pwdtext.leftviewmode = UITextFieldviewmode.Always
// Do any additional seuitup after loading the view,typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
if (textField == self.text) {
textField.resignFirstResponder()
// self.view.becomeFirstResponder()
}
return true;
}
override func touchesBegan(touches: NSSet,withEvent event: UIEvent) {
self.text.resignFirstResponder()
self.pwdtext.resignFirstResponder()
}
}