UITextField placeholder text color

iOS6 and Later 改变UITextField 中占位符 提示文本的文字颜色

在新版本中(iOS6以后)iOS提供一种 Key = value 属性的方式,来改变UI的属性内容。
以UITextField为例

?





1

@property(nonatomic,copy) NSAttributedString
*attributedText NS_AVAILABLE_IOS(6_0); // default is nil

  

attributedText 为UITextField 的 public 属性
可以通过键值对的方式来改变 UITextField的内容

例如:

?





1

2

3

4

5

6

7

8

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之前可以重写

?





1

-(void)drawPlaceholderInRect:(CGRect)rect;

  

例如:

?





1

2

3

4

5

-(void) drawPlaceholderInRect:(CGRect)rect

{

[[UIColor blueColor] setFill];

[[self
placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];

}

  

还有一些其他的方法可以重写控件

当然 你也可以继承UITextField 自定义自己的控件 实现的自定义方法
一般就是 以下几种:

?





1

2

3

4

5

6

7

8

9

10

- (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,布布扣,bubuko.com

时间: 2024-08-08 15:14:21

UITextField placeholder text color的相关文章

IOS_改变UITextField placeHolder颜色、字体

IOS_改变UITextField placeHolder颜色.字体 我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段的显示行为.这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围,甚至修改placeHolder颜色,字体. – textRectForBounds:     //重写来重置文字区域 – drawTextInRect:        //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函

改变UITextField placeHolder色彩、字体

改变UITextField placeHolder颜色.字体 我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段的显示行为.这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围,甚至修改placeHolder颜色,字体. – textRectForBounds:     //重写来重置文字区域 – drawTextInRect:        //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不

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 searching How to change the text color of the statusbar to dark color on android 4.4 The default text color is white, like this I'd like to change the topmo

占位符(placeholder text)

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

修改 UITextfield placeholder 颜色

_password = [[UITextField alloc]init]; _password.font = k18Font; _password.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@" 密码" attributes:@{NSForegroundColorAttributeName:kBlackColor}]; ***************** 而且 UITextField 比 UIL

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

本文转载至 http://m.blog.csdn.net/blog/a394318511/8025170 我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段的显示行为.这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围,甚至修改placeHolder颜色,字体. – textRectForBounds:     //重写来重置文字区域 – drawTextInRect:        //改变绘文字属性.重写时调用super可以按默

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

我们有时需要定制化UITextField对象的风格,可以添加许多不同的重写方法,来改变文本字段的显示行为.这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围,甚至修改placeHolder颜色,字体. – textRectForBounds:     //重写来重置文字区域 – drawTextInRect:        //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了. – placeholderRectFor

IOS UITextField. placeholder属性这个提示符的大小和颜色

用UITextField都知道,默认有个提示,原理是kvc,监听, textField.placeholder = @"This is textField.placeholder"; [textField setValue:[UIColor green] forKeyPath:@"_placeholderLabel.textColor"]; [textField setValue:[UIFont boldSystemFontOfSize:15] forKeyPath

iOS searchbar textfield placeholder color

// Get the instance of the UITextField of the search bar UITextField *searchField = [searchBar valueForKey:@"_searchField"]; // Change search bar text color searchField.textColor = [UIColor redColor]; // Change the search bar placeholder text co