[英]make UITextField placeholder text bold
我已经在界面生成器中为UITextField设置了占位符。 现在,如何使占位符文本加粗?
请使用以下代码解决您的问题。
UIColor *color = [UIColor blackColor];
UIFont* boldFont = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
[self.textField setFont:boldFont];
self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Test" attributes:@{NSForegroundColorAttributeName: color}];
可能对您有所帮助。
最简单的方法是,如果更改UITextField
的属性(字体,大小等),它也将应用于占位符。 只需更改UITextField
的属性并查看效果即可。
编辑:
然后在您的UITextField
委托方法中将此属性再次设置为normal。
- (void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor blackColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:14]];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.