标签:true iOS textField func print UItextField Swift UITextField view
//
// ViewController.swift
// Label
//
// Created by 赵士军 on 2019/11/18.
// Copyright © 2019 赵士军. All rights reserved.
//
import UIKit
class ViewController: UIViewController ,UITextFieldDelegate{
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.getTextField()
}
@objc func getTextField(){
self.view.backgroundColor = .red
let textField = UITextField.init(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
textField.placeholder = "请输入"
textField .becomeFirstResponder()
textField.textAlignment = .left
textField.delegate=self
textField.font = .systemFont(ofSize: 15)
textField.center=self.view.center
textField.keyboardType = .default
textField.borderStyle = .roundedRect
textField.clearButtonMode = .whileEditing
textField.isSecureTextEntry = false
textField.leftViewMode = .always
textField.rightViewMode = .always
let leftButton = UIButton(type: .infoDark)
leftButton.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
textField.leftView = leftButton
let rightButton = UIButton(type: .contactAdd)
rightButton.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
textField.rightView = rightButton
textField.keyboardAppearance = UIKeyboardAppearance.alert
self.view .addSubview(textField)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view .endEditing(true)
}
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
print("将要开始编辑")
return true
}
func textFieldDidBeginEditing(_ textField: UITextField) {
print("已经开始编辑")
}
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
print("将要结束编辑")
return true
}
func textFieldDidEndEditing(_ textField: UITextField) {
print("已经结束编辑")
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
print("文本输入内容将要发生变化(每次输入都会调用)")
return true
}
func textFieldShouldClear(_ textField: UITextField) -> Bool {
print("将要清除输入内容,返回值是是否要清除掉内容")
return true
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
print("将要按下Return按钮,返回值是是否结束输入(是否失去焦点)")
return true
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
标签:true,iOS,textField,func,print,UItextField,Swift,UITextField,view 来源: https://www.cnblogs.com/ZsjXxy/p/11883729.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。