UITextField 相关
1. Placeholder 的颜色和字体
@implementation DZCustomTextField
// 设置Placeholder
- (void)customWithPlaceholder: (NSString *)placeholder color: (UIColor *)color font: (UIFont *)font {
// 方法一:修改attributedPlaceholder;
self.attributedPlaceholder = [NSAttributedString attributedStringWithString:placeholder color:color font:font];
// 方法二:使用KVC,最为简单
// self.placeholder = placeholder;
// [self setValue:color forKeyPath:@"_placeholderLabel.color"];
// [self setValue:font forKeyPath:@"_placeholderLabel.font"];
}
// 重写这个方法是为了使Placeholder居中,如果不写会出现类似于下图中的效果,文字稍微偏上了一些
- (void)drawPlaceholderInRect:(CGRect)rect {
[super drawPlaceholderInRect:CGRectMake(0, self.height * 0.5 - 1, 0, 0)];
}
@end
posted on 2016-10-22 17:44 Jackyzhong123 阅读(133) 评论(0) 收藏 举报
浙公网安备 33010602011771号