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的更多相关文章

  1. 改变UITextField placeHolder色彩、字体

    改变UITextField placeHolder颜色.字体 我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段的显示行为.这些方法都会返回一个CGRect ...

  2. 占位符(placeholder text)

    占位符(placeholder text)是用户在input(输入)框输入任何东西之前放置在input(输入)框中的预定义文本. 你可以用如下方式创建占位符: <input type=" ...

  3. 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 ...

  4. Cross-Browser HTML5 Placeholder Text

    One of the nice enhancement in HTML5 web form is being able to add placeholder text to input fields. ...

  5. 修改UITextField Placeholder的颜色

    修改UITextField Placeholder的颜色 1 第一种情况只是修改颜色等文字属性 创建属性字典 NSDictionary *attrsDic = @{ NSForegroundColor ...

  6. Android Text Color设置不当造成信息不显示

    Android Text Color设置不当造成信息不显示 Android 的TextView 可以设置颜色,默认我们可以设置成 #000000 ,但某一次设置成了#00000000 ,就是多了两个0 ...

  7. 修改UITextField placeholder Color

    [YourtextField setValue:[UIColor colorWithRed:97.0/255.0 green:1.0/255.0 blue:17.0/255.0 alpha:1.0] ...

  8. [转]改变UITextField placeHolder颜色、字体

    本文转载至 http://m.blog.csdn.net/blog/a394318511/8025170 我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段 ...

  9. (转) 改变UITextField placeHolder颜色、字体 、输入光标位置等

    我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段的显示行为.这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围,甚至修改placeHo ...

随机推荐

  1. 省选算法学习-dp优化-四边形不等式

    嗯......四边形不等式的确长得像个四边形[雾] 我们在dp中,经常见到这样一类状态以及转移方程: 设$dp\left[i\right]\left[j\right]$表示闭区间$\left[i,j\ ...

  2. 刷题总结——纸带(NOIP赛前模拟)

    题目: 有一个无限长的纸带··上面被划分为若干个格子··现在进行N次操作,第i次操作在L到R上擦出曾经写上的数字(如果有),并写上数字i,询问最终可以看到多少个数字 N小于10^6 题解: 首先毫无疑 ...

  3. 论文笔记《Fully Convolutional Networks for Semantic Segmentation》

    一.Abstract 提出了一种end-to-end的做semantic segmentation的方法,也就是FCN,是我个人觉得非常厉害的一个方法. 二.亮点 1.提出了全卷积网络的概念,将Ale ...

  4. 321. Create Maximum Number 解题方法详解

    321. Create Maximum Number 题目描述 Given two arrays of length m and n with digits 0-9 representing two ...

  5. javasript深度拷贝

    1 将json数据转换为字符串形式 var j={"name":"daenerys targaryen","dragon":"{& ...

  6. 美食节(bzoj 2879)

    Description CZ市为了欢迎全国各地的同学,特地举办了一场盛大的美食节.作为一个喜欢尝鲜的美食客,小M自然不愿意错过这场盛宴.他很快就尝遍了美食节所有的美食.然而,尝鲜的欲望是难以满足的.尽 ...

  7. SPOJ QTREE4 SPOJ Query on a tree IV

    You are given a tree (an acyclic undirected connected graph) with N nodes, and nodes numbered 1,2,3. ...

  8. 【POJ3667】Hotel(线段树)

    题意:有n个依次编号的元素,要求维护以下两个操作: 1.询问整个数列中是否有长度>=x的连续的一段未被标记的元素,若无输出0,若有输出最小的开始编号ans并将[ans,ans+x-1]标记 2. ...

  9. jQuery1.4与json格式兼容问题

    原文发布时间为:2010-10-10 -- 来源于本人的百度文章 [由搬家工具导入] 原来使用jQuery1.3.2编写的代码,更换到1.4.2后,使用jQuery.ajax()加载的json文件,不 ...

  10. Servlet乱码解决

    后端收前端 1.post乱码 可以通过 request.setCharacterEncoding("utf-8");  这样在后端可以接收中文 2.get乱码(手动解决) 可以通过 ...