UITextField swift

//
// ViewController.swift
// UILabelTest
//
// Created by mac on 15/6/23.
// Copyright (c) 2015年 fangyuhao. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UITextFieldDelegate {

override func viewDidLoad() {
    super.viewDidLoad()

    var textField = UITextField(frame: CGRectMake(10, 160, 200, 30))
    textField.borderStyle = UITextBorderStyle.RoundedRect
    //设置文本样式
    textField.placeholder = "请输入用户名"//设置提示文字
    textField.text = "holyantholyantholyantho"
    textField.adjustsFontSizeToFitWidth = true
    textField.minimumFontSize = 14//指定最小可缩小的字号
    textField.textAlignment = NSTextAlignment.Center//设置对其方式
    //键盘设置
    textField.returnKeyType = UIReturnKeyType.Go//设置return建属性
    textField.delegate = self
    //清除按钮
    textField.clearButtonMode = UITextFieldViewMode.WhileEditing
    //背景设置
    textField.background = UIImage(named: "background")

    self.view.addSubview(textField)



    // Do any additional setup 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 {
    //收起键盘
    textField.resignFirstResponder()
    println(textField.text)
    return true
}

}

posted @ 2016-12-16 23:54  乱笙歌  阅读(123)  评论(0编辑  收藏  举报