ios修改textField的placeholder的字体颜色大小
2016-04-27 10:41
716 查看
ios修改textField的placeholder的字体颜色大小
前言
设置UITextField的placeholder的颜色代码片段:1 2 3 4 5 | textField.placeholder = @"username is in here!"; [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"]; |
1 2 3 4 5 6 7 8 9 10 11 12 13 | UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; NSString *holderText = @"标哥的技术博客"; NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:holderText]; [placeholder addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, holderText.length)]; [placeholder addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16] range:NSMakeRange(0, holderText.length)]; textField.attributedPlaceholder = placeholder; [cell.contentView addSubview:textField]; |
_placeholderLabel说明
1 2 3 4 | (lldb) po [textField valueForKey:@"_placeholderLabel"] <UITextFieldLabel: 0x13fe835f0; frame = (0 0; 0 0); text = '标哥的技术博客'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x13fe855f0>> |
说明
iOS6.0之后,有attributedPlaceholder属性,因此可以直接通过它设置。在iOS6.0之前,可以通过KVC来设置_placeholderLabel的属性值。
相关文章推荐
- iOS的edgesForExtendedLayout、automaticallyAdjustsScrollViewInsets属性
- iOS image.size大小实际输出的值跟图片像素的关系
- ios 性能优化之ImageView的那些事
- iOS 生成随机数
- iOS开发之KVC全解
- IOS 读二进制数据文件
- iOS tableViewCell 代理
- iOS_时间戳与时间间的互相转化
- iOS~runtime理解
- iOS 导航栏去阴影
- iOS 通知传值
- 如何使用iOS预编译头文件
- iOS-MD5加密32位扩展类
- 基于JS实现Android,iOS一个手势动画效果
- 2015年11月Xcode7.1(7B91b)打包发布苹果iOS应用指南
- iOS开发-加在透明视图上的控件会透明
- iOS 8新特性之扩展
- iOS-开发常用宏
- 更新版本流程 ios
- 【代码笔记】iOS-拍照动画