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.
        }
        */
    
    }
  • 相关阅读:
    HDU4405(期望DP)
    hdu4165(简单递推,实则卡特兰数的应用)
    hdu4576(概率DP)
    期望DP(2013山东省赛)
    Nim游戏及其相关拓展
    nginx ubuntu环境下配置 path_info
    iOS 瀑布流的简单实现 UICollectionView
    ThPullRefresh (Swift 版)下拉上拉刷新
    用php搭建博客系统-待续
    面试收录-php面试题
  • 原文地址:https://www.cnblogs.com/xujiahui/p/6952286.html
Copyright © 2011-2022 走看看