1. 设置占位图片以及文字颜色 字体大小
for (UIView *subViewin self.favoriteSearchBar.subviews)
{
for (UIView *secondLevelSubviewin subView.subviews){
if ([secondLevelSubviewisKindOfClass:[UITextFieldclass]])
{
UITextField *searchBarTextField = (UITextField *)secondLevelSubview;
//set font color here
searchBarTextField.textColor = [UIColorredColor];
searchBarTextField.font = [FontfontWithType:FontTypeFZLanTingHei_L_GBKsize:14];
//placeHolder文字设置
// UIColor *color = [UIColor whiteColor];
// searchBarTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用户名" attributes:@{NSForegroundColorAttributeName: color}];
// [searchBarTextField setValue:[UIColorwhiteColor] forKeyPath:@"_placeholderLabel.textColor"];
break;
}
}
}
2. 设置背景颜色 也是第二层 subView
for (UIView *subview in searchBar.subviews)
{
for (UIView *sub in subview.subviews) {
if ([sub isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
//选择清空或者 其他颜色
[sub removeFromSuperview];
break;
}
}
}