[英]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.