UITextField placeholder text color
iOS6 and Later 改变UITextField 中占位符 提示文本的文字颜色
在新版本中(iOS6以后)iOS提供一种 Key = value 属性的方式,来改变UI的属性内容。
以UITextField为例
@property(nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil
attributedText 为UITextField 的 public 属性 可以通过键值对的方式来改变 UITextField的内容
例如:
if([textField respondsToSelector:@selector(setAttributedPlaceholder:)]
{
UIColor*color =[UIColor blackColor];
textField.attributedPlaceholder =[[NSAttributedString alloc] initWithString:placeholderText attributes:@{NSForegroundColorAttributeName: color}];
}else{
NSLog(@"Cannot set placeholder text's color, because deployment target is earlier than iOS 6.0");
// TODO: Add fall-back code to set placeholder color.
}
#iOS6 Earlier
iOS6之前可以重写
-(void)drawPlaceholderInRect:(CGRect)rect;
例如:
-(void) drawPlaceholderInRect:(CGRect)rect
{
[[UIColor blueColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
}
还有一些其他的方法可以重写控件
当然 你也可以继承UITextField 自定义自己的控件 实现的自定义方法
一般就是 以下几种:
- (CGRect)borderRectForBounds:(CGRect)bounds;
- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)placeholderRectForBounds:(CGRect)bounds;
- (CGRect)editingRectForBounds:(CGRect)bounds;
- (CGRect)clearButtonRectForBounds:(CGRect)bounds;
- (CGRect)leftViewRectForBounds:(CGRect)bounds;
- (CGRect)rightViewRectForBounds:(CGRect)bounds; - (void)drawTextInRect:(CGRect)rect;
- (void)drawPlaceholderInRect:(CGRect)rect;
UITextField placeholder text color的更多相关文章
- 改变UITextField placeHolder色彩、字体
改变UITextField placeHolder颜色.字体 我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段的显示行为.这些方法都会返回一个CGRect ...
- 占位符(placeholder text)
占位符(placeholder text)是用户在input(输入)框输入任何东西之前放置在input(输入)框中的预定义文本. 你可以用如下方式创建占位符: <input type=" ...
- How to change statusbar text color to dark on android 4.4
Because I haven't enough votes, so post picture at here, thank you. Almost 2 weeks ago, I was search ...
- Cross-Browser HTML5 Placeholder Text
One of the nice enhancement in HTML5 web form is being able to add placeholder text to input fields. ...
- 修改UITextField Placeholder的颜色
修改UITextField Placeholder的颜色 1 第一种情况只是修改颜色等文字属性 创建属性字典 NSDictionary *attrsDic = @{ NSForegroundColor ...
- Android Text Color设置不当造成信息不显示
Android Text Color设置不当造成信息不显示 Android 的TextView 可以设置颜色,默认我们可以设置成 #000000 ,但某一次设置成了#00000000 ,就是多了两个0 ...
- 修改UITextField placeholder Color
[YourtextField setValue:[UIColor colorWithRed:97.0/255.0 green:1.0/255.0 blue:17.0/255.0 alpha:1.0] ...
- [转]改变UITextField placeHolder颜色、字体
本文转载至 http://m.blog.csdn.net/blog/a394318511/8025170 我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段 ...
- (转) 改变UITextField placeHolder颜色、字体 、输入光标位置等
我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段的显示行为.这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围,甚至修改placeHo ...
随机推荐
- Codeforces Round #316 (Div. 2) A 水
A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- javaScript 笔记(4) -- 弹窗 & 计时事件 & cookie
弹窗 可以在 JavaScript 中创建三种消息框:警告框.确认框.提示框. 警告框:经常用于确保用户可以得到某些信息. 当警告框出现后,用户需要点击确定按钮才能继续进行操作. 语法: window ...
- nodeJS学习(11)--- nodeJS 取参 -- req.body & req.query & req.params
参考:https://my.oschina.net/u/2519530/blog/535309 获取请求中的参数是每个web后台处理的必经之路,nodejs的 express框架 提供了四种方法来实现 ...
- Python(2)-- 运算符
1. 算术运算符 常规: 加(+).减(-).乘(*).除(/).取模(%) 此外: 幂(**):返回x的y次幂, eg: 2**3---返回 2 的 5 次幂,输出结果32 取整除(//):返回商的 ...
- Codeforces Round #393 (Div. 2)
A. Petr and a calendar time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- shell文本过滤编程(一):grep和正则表达式【转】
转自:http://blog.csdn.net/shallnet/article/details/38799739 版权声明:本文为博主原创文章,未经博主允许不得转载.如果您觉得文章对您有用,请点击文 ...
- Selenium2+python自动化(学习笔记2)
from selenium import webdriverdriver = webdriver.Ie()driver.get=("http://www.baidu.com")dr ...
- C#反射(Reflection)详解
1. 什么是反射2. 命名空间与装配件的关系3. 运行期得到类型信息有什么用4. 如何使用反射获取类型5. 如何根据类型来动态创建对象6. 如何获取方法以及动态调用方法7. 动态创建委托 1.什么是反 ...
- AC日记——黑魔法师之门 codevs 1995
1995 黑魔法师之门 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 经过了16个工作日的紧张 ...
- 10.1综合强化刷题 Day1
a[问题描述]你是能看到第一题的 friends 呢.——hja何大爷对字符串十分有研究,于是天天出字符串题虐杀 zhx.何大爷今天为字符串定义了新的权值计算方法.一个字符串由小写字母组成,字符串的权 ...