通过NSAttributeString方法来更改占位文字的属性
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//文字属性
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSForegroundColorAttributeName] = [UIColor grayColor];
//带有属性的文字(富文本属性)NSAttributeString
NSAttributedString *attr = [[NSAttributedString alloc] initWithString:@"手机号" attributes:dict];
self.phoneField.attributedPlaceholder = attr;
}
//画出占位文字- (void)drawPlaceholderInRect:(CGRect)rect {
[self.placeholder drawInRect:CGRectMake(0, 13, self.size.width, 25) withAttributes:@{
NSForegroundColorAttributeName : [UIColor grayColor],
NSFontAttributeName : [UIFont systemFontOfSize:14]
}];
}
(void)initialize {
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UITextField class] , &count);
for (int i = 0; i < count; i++) {
//取出成员变量
Ivar ivar = *(ivars + i);
//打印成员变量名字
DDZLog(@"%s",ivar_getName(ivar));
}
}
- (void)awakeFromNib {
//修改占位文字颜色
[self setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"]; //设置光标颜色和文字颜色一致
self.tintColor = self.textColor;
}
//获得焦点时
- (BOOL)becomeFirstResponder {
//改变占位文字颜色
[self setValue:self.textColor forKeyPath:@"_placeholderLabel.textColor"]; return [super becomeFirstResponder];
}
//失去焦点时
- (BOOL)resignFirstResponder {
//改变占位文字颜色
[self setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"]; return [super resignFirstResponder];
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有