(IOS)修改UISearchBar的占位文字颜色
2018-08-10 本文已影响0人
rightmost
// 方法一(推荐使用)
UITextField*searchField = [searchBarvalueForKey:@"_searchField"];
[searchFieldsetValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];
// 方法二(已过期)
[[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor]];
// 方法三(已过期)
NSDictionary *placeholderAttributes = @{NSForegroundColorAttributeName : [UIColor redColor], NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:15],};
NSAttributedString*attributedPlaceholder = [[NSAttributedString alloc] initWithString:searchBar.placeholder attributes:placeholderAttributes];
[[UITextField appearanceWhenContainedIn:[UISearchBar class],nil] setAttributedPlaceholder:attributedPlaceholder];