如何使用swift 2.0更改UITextfield占位符颜色和fontsize? [英] How to change UITextfield placeholder color and fontsize using swift 2.0?

查看:116
本文介绍了如何使用swift 2.0更改UITextfield占位符颜色和fontsize?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改 UITextfield 占位符& SWIFT 2.0中 fontsize

How to change UITextfield placeholder & fontsize in SWIFT 2.0?

推荐答案

#1。以编程方式设置占位符文本字段颜色

    var myMutableStringTitle = NSMutableAttributedString()
    let Name  = "Enter Title" // PlaceHolderText

    myMutableStringTitle = NSMutableAttributedString(string:Name, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 20.0)!]) // Font
    myMutableStringTitle.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range:NSRange(location:0,length:Name.characters.count))    // Color
    txtTitle.attributedPlaceholder = myMutableStringTitle

OR

txtTitle.attributedPlaceholder = NSAttributedString(string:"Enter Title", attributes: [NSForegroundColorAttributeName: yellowColor])

注意:名称 textField 的占位符。

PlaceHolder TextFiled:

--------------- - - - - - - - - - 要么 - - - - - - - - - - - - - - - - -----

#2。在运行时属性设置占位符文本字段颜色


  1. 设置textfield placeHolder文本输入标题

单击textfield属性的身份检查器。

Click on identity inspector of textfield property.

用户定义运行时属性,添加颜色属性

User Define Runtime Attributes, add color attributes

密钥路径: _placeholderLabel.textColor

类型:颜色

值:您的颜色或RGB值

PlaceHolder TextFiled:

这篇关于如何使用swift 2.0更改UITextfield占位符颜色和fontsize?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆