iOS 13 设置 UISearchBar 的 Placehol
2019-10-22 本文已影响0人
陪你宿醉的人注定无法送你回家
.h 中类方法
+ (void)setPlaceholderForTextField:(UITextField*)textFieldwithFont:(UIFont*)fontandColor:(UIColor*)textColorandPlaceholderText:(NSString*)placeholder;
.m 中实现
+ (void)setPlaceholderForTextField:(UITextField*)textFieldwithFont:(UIFont*)fontandColor:(UIColor*)textColorandPlaceholderText:(NSString*)placeholder{
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName:textColor,NSFontAttributeName:font}];
textField.attributedPlaceholder= attrString;
}
使用方法
*UISearchBar中有searchTextField 属性
[MyUtil setPlaceholderForTextField:_searchBar.searchTextField withFont:[UIFont systemFontOfSize:13] andColor:[UIColor greenColor] andPlaceholderText:@"提示内容"];