IOS 修改UISearchBar 輸入框的顏色 placeholder字型的顏色
阿新 • • 發佈:2019-02-06
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 setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"]; //修改placeholder的顏色
} else if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
}
}