IOS 修改UISearchBar 输入框的颜色 placeholder字体的颜色
UISearchBar *searchBar = [UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
for (UIView* subview in [[searchBar.subviews lastObject] subviews]) {
if ([subview isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField*)subview;
textField.textColor = [UIColor redColor]; //修改输入字体的颜色
[textField setBackgroundColor:[UIColor grayColor]]; //修改输入框的颜色
[textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"]; //修改placeholder的颜色
} else if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
}
}