.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:@"提示内容"];
网友评论