Swift 设置UITextField的placeholder的字体大小、颜色

来源:互联网 发布:大数据开发工程师招聘 编辑:程序博客网 时间:2024/06/06 08:29

扩展类代码

////  UITextField+Extension.swift//  KriFationClient//  Created by qingxun on 2017/9/5.//  Copyright © 2017年 BruceLv. All rights reserved.//import Foundationimport UIKitextension UITextField{    //MARK:-设置暂位文字的颜色    var placeholderColor:UIColor {        get{            let color =   self.value(forKeyPath: "_placeholderLabel.textColor")            if(color == nil){                return UIColor.white;            }            return color as! UIColor;        }        set{          self.setValue(newValue, forKeyPath: "_placeholderLabel.textColor")        }    }//MARK:-设置暂位文字的字体    var placeholderFont:UIFont{        get{            let font =   self.value(forKeyPath: "_placeholderLabel.font")            if(font == nil){                return UIFont.systemFont(ofSize: 14);            }            return font as! UIFont;        }        set{         self.setValue(newValue, forKeyPath: "_placeholderLabel.font")        }    }}

调用示例

        let tf = UITextField()        tf.placeholder = "一段暂位文字"        tf.placeholderFont = FONT(32);        tf.placeholderColor = UIColor.white;        tf.textAlignment = .center;        tf.textColor = .white;
阅读全文
0 0