UITextField的使用

UITextField的使用

mport UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.setupTextField()
    }
    
    func setupTextField() {
        // 创建textField
        let textField = UITextField(frame: CGRect(x: 100, y: 100, width: 100, height: 40))
        // 设置输入框的边框样式
        /**
         public enum UITextBorderStyle : Int {
         case none  无边框
         case line  直线边框
         case bezel 边线+阴影
         case roundedRect   圆角矩形边框
         }
         */
        textField.borderStyle = .none
        // 设置提示文字
        textField.placeholder = "请输入相关文字"
        // 设置使用*** 显示, 如密码
        textField.isSecureTextEntry = true
        // 当文字超出文本框宽度时,自动调整文字大小
        textField.adjustsFontSizeToFitWidth = true
        // 最小可缩小的字号
        textField.minimumFontSize = 12.0
        // 水平对齐
        /**
         public enum NSTextAlignment : Int {
         
         case left // Visually left aligned
         case center // Visually centered
         case right // Visually right aligned
         case justified // Fully-justified. The last line in a paragraph is natural-aligned.
         case natural // Indicates the default alignment for script
         }
         */
        textField.textAlignment = .center
        // 垂直对齐
        /**
         public enum UIControlContentVerticalAlignment : Int {
         
         case center    垂直居中对齐
         case top       垂直向上对齐
         case bottom    垂直向下对齐
         case fill
         }

         */
        textField.contentVerticalAlignment = .top
        
        // 设置背景图片,先要去除边框样式
        textField.borderStyle = .none
        textField.background = UIImage(named: "back")
        // 清除按钮
        /**
         public enum UITextFieldViewMode : Int {
         
         case never         从不出现
         case whileEditing  编辑时出现清除按钮
         case unlessEditing 编辑时不出现,编辑后才出现清除按钮
         case always        一直显示清除按钮
         }
         */
        textField.clearButtonMode = .whileEditing
        // 键盘类型
        /**
         public enum UIKeyboardType : Int {
         
         
         case `default` // Default type for the current input method.   系统默认的虚拟键盘
         case asciiCapable // Displays a keyboard which can enter ASCII characters  显示英文字母的虚拟键盘
         case numbersAndPunctuation // Numbers and assorted punctuation.    显示数字和标点的虚拟键盘
         case URL // A type optimized for URL entry (shows . / .com prominently).   显示便于输入数字的虚拟键盘
         case numberPad // A number pad with locale-appropriate digits (0-9, ۰-۹, ०-९, etc.). Suitable for PIN entry.   显示便于输入数字的虚拟键盘
         case phonePad // A phone pad (1-9, *, 0, #, with letters under the numbers).   显示便于拨号呼叫的虚拟键盘
         case namePhonePad // A type optimized for entering a person's name or phone number.    显示便于聊天拨号的虚拟键盘
         case emailAddress // A type optimized for multiple email address entry (shows space @ . prominently).  显示便于输入Email的虚拟键盘
         @available(iOS 4.1, *)
         case decimalPad // A number pad with a decimal point.  显示用于输入数字和小数点的虚拟键盘
         @available(iOS 5.0, *)
         case twitter // A type optimized for twitter text entry (easy access to @ #)   显示方便些Twitter的虚拟键盘
         @available(iOS 7.0, *)
         case webSearch // A default keyboard type with URL-oriented addition (shows space . prominently).  显示便于在网页上书写的虚拟键盘
         @available(iOS 10.0, *)
         case asciiCapableNumberPad // A number pad (0-9) that will always be ASCII digits.
         public static var alphabet: UIKeyboardType { get } // Deprecated
         }
         */
        textField.keyboardType = .default
        // 成为第一响应者
        textField.becomeFirstResponder()
        // 放弃第一响应者
        textField.resignFirstResponder()
        // 设置键盘return键的样式
        /**
         public enum UIReturnKeyType : Int {
         
         case `default`
         case go    表示完成输入,同时会跳到另一页
         case google
         case join  表示注册用户或添加数据
         case next  表示继续下一步
         case route
         case search    表示搜索
         case send  表示继续下一步
         case yahoo
         case done  表示完成输入
         case emergencyCall
         @available(iOS 9.0, *)
         case `continue`
         }
         */
        textField.returnKeyType = .done
        // 设置代理
        textField.delegate = self
        
        // 设置attributedPlaceholder
        // 1. 创建属性字典,存放需要修改的属性
        var attributed:[String: AnyObject] = NSMutableDictionary() as! [String: AnyObject]
        attributed[NSFontAttributeName] = UIFont.systemFont(ofSize: 13)
        // 2. 创建带属性的字符串
        let string:NSAttributedString = NSAttributedString.init(string: "你还好嘛,hello world", attributes: attributed)
        // 3. 设置placeholder属性
        textField.attributedPlaceholder = string
        
        /**
         public enum UITextFieldViewMode : Int {
         
         case never
         case whileEditing
         case unlessEditing
         case always
         }
         */
        textField.leftView = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
        textField.leftViewMode = .always
        
        
        self.view.addSubview(textField)
        
    
    }

}

extension ViewController: UITextFieldDelegate {

    // 点击return键时调用
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        return true
    }
    
    // 将要开始输入的时候调用
    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        
        return true
    }
    
    // 已经开始输入
    func textFieldDidBeginEditing(_ textField: UITextField) {
        
    }
    
    // 将要结束输入时调用
    func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
       return true
    }
    
    // 已经输入结束
    func textFieldDidEndEditing(_ textField: UITextField) {
        
    }
    
    // 清除文字按钮的点击事件
    func textFieldShouldClear(_ textField: UITextField) -> Bool {
        return true
    }
    
}


作者:不安分心
链接:https://www.jianshu.com/p/2552785b4138
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值