修改UITextField的placeholder颜色
2016-04-16 23:09
387 查看
修改UITextField的placeholder颜色
使用属性@property(nonatomic,copy) NSAttributedString *attributedPlaceholder; // 文字属性 NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSForegroundColorAttributeName] = [UIColor grayColor]; // NSAttributedString : 带有属性的文字(富文本技术) NSAttributedString *placeholder = [[NSAttributedString alloc] initWithString:@"手机号" attributes:attrs]; self.phoneField.attributedPlaceholder = placeholder; NSMutableAttributedString *placehoder = [[NSMutableAttributedString alloc] initWithString:@"手机号"]; [placehoder setAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} range:NSMakeRange(0, 1)]; [placehoder setAttributes:@{ NSForegroundColorAttributeName : [UIColor yellowColor], NSFontAttributeName : [UIFont systemFontOfSize:30] } range:NSMakeRange(1, 1)]; [placehoder setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} range:NSMakeRange(2, 1)]; self.phoneField.attributedPlaceholder = placehoder;
重写方法
- (void)drawPlaceholderInRect:(CGRect)rect { [self.placeholder drawInRect:CGRectMake(0, 10, rect.size.width, 25) withAttributes:@{ NSForegroundColorAttributeName : [UIColor grayColor], NSFontAttributeName : self.font}]; }
使用KVC
[self setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
运行时(Runtime)
苹果官方一套C语言库能做很多底层操作(比如访问隐藏的一些成员变量\成员方法….)
访问成员变量举例
unsigned int count = 0; // 拷贝出所有的成员变量列表 Ivar *ivars = class_copyIvarList([UITextField class], &count); for (int i = 0; i<count; i++) { // 取出成员变量 // Ivar ivar = *(ivars + i); Ivar ivar = ivars[i]; // 打印成员变量名字 XMGLog(@"%s", ivar_getName(ivar)); } // 释放 free(ivars);
相关文章推荐
- Assurance 4000 Techniques for Industrial Control Systems (ICS)
- Ubiquitous Religions(sdut_2428)
- requirejs 学习
- getRequestURL、getRequestURI、getContextPath、getServletPath和getRealPath的区别
- UI更新方法Handler和runOnUiThread
- UIImage imageName方法扩充提醒功能
- hdu 5667Sequence
- 【Arduino官方教程第一辑】示例程序 1-4 读取数字引脚
- HDU 5667 Sequence
- 第83课:使用Scala和Java两种方式实战Spark Streaming开发 本地webui小技巧
- 【Arduino官方教程第一辑】示例程序 1-3 点亮LED
- 1.UIRoot:根据高度自适应屏幕分辨率。
- iOS 去掉UITableView风格为group时候的最顶部的空白距离
- EasyUI 使用
- EasyUI-datebox formatter
- 【hdu1711】Number Sequence——KMP
- 最长递增子序列O(NlogN)算法(leetcode 300. Longest Increasing Subsequence )
- Jersey(1.19.1) - Building URIs
- 【Arduino官方教程第一辑】示例程序 1-2 Arduino工程的最小单元
- Android UI学习笔记 之 ActionMode不能覆盖Toolbar解决方案