zoukankan      html  css  js  c++  java
  • Swift3.0 UITextField

    import UIKit
    
    private var textfieldd = UITextField()
    class TextFieldViewController: UIViewController,UITextFieldDelegate {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Do any additional setup after loading the view.
            
            //设置大小
            textfieldd.frame = CGRect(x: 0, y: 100,  300, height: 50)
            
             // 设置 样式 (.none 无边框  .line 直线边框  .roundedRect 圆角矩形边框  .bezel 边线+阴影)
            textfieldd.borderStyle = .roundedRect
            
            //提示字
            textfieldd.placeholder = "提示字"
            textfieldd.textColor = UIColor.blue
            textfieldd.font = UIFont.boldSystemFont(ofSize: 20)
            textfieldd.textAlignment = .right
           
            // 设置 文字超出文本框时自适应大小
            textfieldd.adjustsFontSizeToFitWidth = true
            // 设置 最小可缩小的字号
            textfieldd.minimumFontSize = 14
            
            //清理按钮
            textfieldd.clearButtonMode = .whileEditing
            
            //键盘样式
            textfieldd.keyboardType = .default
            
            textfieldd.delegate = self
            
            
            
            self.view.addSubview(textfieldd)
            
        }
        
        
        ////////////////////////////////代理方法////////////////////////////////////
        // 输入框询问是否可以编辑 true 可以编辑  false 不能编辑
        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 textFieldShouldClear(_ textField: UITextField) -> Bool {
            return true
        }
        // 输入框按下键盘 return 收回键盘
        func textFieldShouldReturn(_ textField: UITextField) -> Bool {
            textField.resignFirstResponder()
            return true
        }
        // 该方法当文本框内容出现变化时 及时获取文本最新内容
        func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
            
            return true
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
        
    
        /*
        // 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.destinationViewController.
            // Pass the selected object to the new view controller.
        }
        */
    
    }
  • 相关阅读:
    C#的委托
    解决.net core3.1使用docker部署在Ubuntu上连接sqlserver报error:35的问题
    【WPF学习】第三十六章 样式基础
    asp.net core 3.x 身份验证-3cookie身份验证原理
    C#设计模式学习笔记:(9)组合模式
    Asp.net Core MVC(三)UseMvc设置路由
    C#后台异步消息队列实现
    ASP.NET CORE 内置的IOC解读及使用
    VS2015发布WEB项目
    C#的冒泡排序
  • 原文地址:https://www.cnblogs.com/xujiahui/p/6952286.html
Copyright © 2011-2022 走看看