Swift 簡單控制項樣本:文字框(UITextField)

來源:互聯網
上載者:User

標籤:ios   swift   文字框   uitextfield   

轉載請聲明出處:http://blog.csdn.net/jinnchang/article/details/44853487
------------------------------------------------------------------------------------------
////  ViewController.swift//  UITextFieldSample////  Created by jinnchang on 15/4/2.//  Copyright (c) 2015年 Jinn Chang. All rights reserved.//import UIKitclass ViewController: UIViewController, UITextFieldDelegate {        var textField: UITextField!    override func viewDidLoad() {        super.viewDidLoad()        // Do any additional setup after loading the view, typically from a nib.                textField = UITextField(frame: CGRectMake(30, 50, self.view.frame.size.width - 60, 40))        textField.borderStyle = .RoundedRect        textField.placeholder = "請輸入內容"        textField.text = "username"        textField.delegate = self                self.view.addSubview(textField)    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.    }        // 進入編輯狀態    func textFieldDidBeginEditing(textField: UITextField) {        println("開始編輯:\(textField.text)")    }        // 結束編輯狀態    func textFieldDidEndEditing(textField: UITextField) {        println("結束編輯:\(textField.text)")    }        // Return 按鈕隱藏鍵盤    func textFieldShouldReturn(textField: UITextField) -> Bool {        textField.resignFirstResponder()        return true    }        // 點擊編輯框外,隱藏鍵盤    override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {        textField.resignFirstResponder()    }}
------------------------------------------------------------------------------------------
GitHub 上項目地址:UITextFieldSample
控制項更多相關屬性及方法參考:UITextField Class Reference
文章最後更新時間:2015年4月3日11:47:37

Swift 簡單控制項樣本:文字框(UITextField)

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.