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. 【CCF】除法 树状数组

    [AC] #include<iostream> #include<math.h> #include<cstring> using namespace std; ty ...

  2. linux下头文件

    aio.h 异步I/Oassert.h 验证程序断言complex 复数类complex.h 复数处理cpio.h cpio归档值ctype.h 字符类型dirent.h 目录项,opendir(), ...

  3. MAC电脑安装Mysql服务器和Navicat for mysql客户端

    1.下载链接 Navicat for mysql客户端 链接: https://pan.baidu.com/s/1dGbzgbR 密码: i43g Mysql服务器 链接: https://pan.b ...

  4. 当文字过长时裁剪(显示省略号或只裁剪 用CSS方法,不用程序)

    原文发布时间为:2009-09-16 -- 来源于本人的百度文章 [由搬家工具导入] CSS中ellipsis()应用【转】 CSS手册中text-overflow属性的定义:   语法: text- ...

  5. java中 文件压缩处理

    public static void main(String[] args) throws IOException { File file=new File("./mhxx_configs. ...

  6. pip源配置

    1.使用配置文件配置文件[global]trusted-host=mirrors.aliyun.comindex-url=http://mirrors.aliyun.com/pypi/simple/ ...

  7. 倒计时器CountDownLatch与同步屏障CyclicBarrier

    CountDownLatch CountDownLatch是一个非常实用的多线程控制工具类,这个工具通常用来控制线程等待,它可以让某一个线程等待直到倒计时结束,再开始执行.在这里指CountDownL ...

  8. DOM-window下的常用子对象-location-刷新页面

    1.刷新当前页面:(通过给location.href赋值的方式) window.location.href="" eg:window.location.href="htt ...

  9. Cryptography I 学习笔记 --- 抗碰撞

    1. 生日攻击,如果hash函数可以产生n bit的结果,那么生日攻击的时间复杂度在O(nn/2)这个量级.以比特币使用的SHA256为例,其hash结果为256bit,那么如果想完成一次生日攻击,那 ...

  10. Educational Codeforces Round 34 B. The Modcrab【模拟/STL】

    B. The Modcrab time limit per test 1 second memory limit per test 256 megabytes input standard input ...