前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IOS UITextField 事件列表

IOS UITextField 事件列表

作者头像
用户5760343
发布2019-07-08 11:46:38
1K0
发布2019-07-08 11:46:38
举报
文章被收录于专栏:sktjsktj
代码语言:javascript
复制
//UITextFieldDelegate
 import UIKit
 class ViewController:UIViewController,UITextFieldDelegate {
 override func viewDidLoad() {
 super.viewDidLoad()
 // Do any additional setup after loading the view,typically from a nib.
 let rect = CGRect(x:10, y:80, width:300, height:
 )
 let textField = UITextField(frame:rect)
 textField.placeholder = “Bank card no”
 textField.autocorrectionType =UITextAutocorrectionType.no
 textField.returnKeyType = UIReturnKeyType.done
 textField.clearButtonMode =UITextFieldViewMode.whileEditing
 textField.keyboardType = UIKeyboardType.numberPad
 textField.keyboardAppearance =
 UIKeyboardAppearance.dark
 textField.delegate = self
 textField.borderStyle = UITextBorderStyle.line
 }
 override func didReceiveMemoryWarning() {
 super.didReceiveMemoryWarning()
 // Dispose of any resources that can be recreated.
 }
 func textFieldShouldBeginEditing(_ textField:UITextField) -> Bool
 // return NO to disallow editing.
 {
 return true
 }
 func textFieldDidBeginEditing(_ textField:UITextField)
 // became first responder
 {
 }
 func textFieldShouldEndEditing(_ textField:UITextField) -> Bool
 // return YES to allow editing to stopand to resign first responder status.NO to disallow the editing session to end
 {
 return true
 }
 func textFieldDidEndEditing(_ textField:UITextField)
 // may be called if forced even if shouldEndEditing returnsNO (e.g.view removed from window) or endEditing:YES called
 {
 }
 func textField(_ textField:UITextField,shouldChangeCharactersIn range:NSRange,replacementString string:String) -> Bool {
 // return NO to not change text
 return true
 }
 func textFieldShouldClear(_ textField:UITextField) -> Bool {
 return true
 }
 func textFieldShouldReturn(_ textField:UITextField)-> Bool {
 return true
 }
 }
//方法包括:
 将要开始编辑状态时调用此协议方法。
 编辑状态开始后调用此协议方法。
 编辑状态将要结束后调用此协议方法。
 编辑状态结束后调用此协议方法。
 协议方法在文本将要输入的时候调用。
 协议方法返回一个BOOL值,指明是否允许根据用户请求清除内容。
 协议方法返回一个BOOL值,指明是否允许在按下Enter键时结束编辑。
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.06.02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档