UITextFieldDelegate
来源:互联网 发布:python多进程读取文件 编辑:程序博客网 时间:2024/05/21 05:20
// UITextField
//
// Created by Catherine on 2017/8/29.
// Copyright © 2017年 Catherine. All rights reserved.
//
import UIKit
class ViewController:UIViewController ,UITextFieldDelegate{
let textField:UITextField =UITextField(frame: CGRect(x: 20, y:100, width: 280, height:40))
overridefunc viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//设置输入框风格为线性
textField.borderStyle =UITextBorderStyle.line
//有凹陷下去的感觉
textField.borderStyle =UITextBorderStyle.bezel
//===提示文字
//设置输入框的提示文字
textField.placeholder ="请输入文字"
//===输入文字
//设置输入的文字颜色
textField.textColor =UIColor.red
//设置文字的字体
textField.font =UIFont.italicSystemFont(ofSize:15)
//设置文字的对齐方式
textField.textAlignment =NSTextAlignment.center
//是否每次点编辑框都清空输入框中的文字
textField.clearsOnBeginEditing =true
textField.backgroundColor =UIColor.magenta
//是否字体大小自适应 字多于框大小时字会变小
textField.adjustsFontSizeToFitWidth =true
//设置输入框为无效
//textField.isEnabled = false
//设置输入框的左视图
let viewLeft:UIView =UIView(frame: CGRect(x:0, y: 0, width:40, height: 40))
let viewRight:UIView =UIView(frame: CGRect(x:0, y: 0, width:40, height: 40))
viewLeft.backgroundColor =UIColor.blue
viewRight.backgroundColor =UIColor.brown
textField.leftView = viewLeft
//textField.rightView = viewRight
//设置左右视图的显示模式 == whileEditing等一些模式
textField.leftViewMode = .always
textField.rightViewMode = .always
//设置弹出的交互键盘
/*在8.0的模拟器中默认是xcode使用电脑键盘作为外接键盘,不再弹出虚拟键盘。如果设置了文本框的inputAccessoryView,那么只会弹出inputAccessoryView,而不会弹出键盘。
*/
let board:UIView =UIView(frame: CGRect(x:0, y: 0, width:320, height: 200))
board.backgroundColor =UIColor.orange
//textField.inputView = board
//设置附键盘视图
textField.inputAccessoryView = board
textField.delegate =self
//显示清除按钮(由下方delegate shouldclear 返回值决定是否能触发)
textField.clearButtonMode =UITextFieldViewMode.always
self.view.addSubview(textField)
}
//对输入文字类型的控制
func textField(_ textField:UITextField, shouldChangeCharactersIn range:NSRange, replacementString string:String) -> Bool {
print(string)
//string 代表输入的新字符
returntrue
}
//已经进入编辑状态时调用的方法
func textFieldDidBeginEditing(_ textField:UITextField) {
print("didbegin")
}
//已经结束编辑状态时调用的方法
func textFieldDidEndEditing(_ textField:UITextField) {
print("didend")
}
//将要进入编辑状态时调用的方法
func textFieldShouldBeginEditing(_ textField:UITextField) -> Bool {
returntrue
//负责无法进入编辑状态
}
//将要结束编辑状态调用的方法
func textFieldShouldEndEditing(_ textField:UITextField) -> Bool {
returntrue
}
func textFieldShouldClear(_ textField:UITextField) -> Bool {
returntrue
}
//点击屏幕收键盘
overridefunc touchesBegan(_ touches:Set<UITouch>, with event:UIEvent?) {
textField.resignFirstResponder()
}
overridefunc didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
- UITextFieldDelegate
- UITextFieldDelegate
- UITextFieldDelegate
- UITextFieldDelegate方法
- UITextFieldDelegate方法
- UITextFieldDelegate中方法说明
- IOS -- UITextFieldDelegate委托代理
- UITextFieldDelegate委托方法注释
- UITextFieldDelegate和tap事件
- UITextFielddelegate委托方法注释
- 使用UITextFieldDelegate来隐藏键盘
- IOS 键盘协议之一 <UITextFieldDelegate>
- iOS键盘协议之一UITextFieldDelegate
- iOS编程-------UITextField UIButton UITextFieldDelegate
- 使用UITextFieldDelegate来隐藏键盘
- iOS UITextFieldDelegate 代理方法小结
- iOS UITextFielddelegate委托方法注释
- 如何使用UITextFieldDelegate来隐藏键盘?
- python 拔取网站
- 优先队列java-PriorityQueue
- Swoole整合ThinkPHP3.2系列教程二
- 记录一次.bat文件执行mysql语句
- CSS与HTML结合的方式
- UITextFieldDelegate
- Linux字符设备驱动之LCD驱动
- text-overflow文本溢出的全兼容CSS代码
- Python 中文编码
- 26 管理事务处理
- kAFL:OS内核的硬件辅助反馈模糊
- 设计模式之适配器模式
- js 简单工厂模式
- 图像分割crop设置 caffe fully convolutional cnn