//设置searchBar Placeholder的字体颜色
// [[UILabel appearanceWhenContainedIn:[_searchBar class], nil] setTextColor:[UIColor grayTextColor]];
// Get the instance of the UITextField of the search bar
UITextField *searchField = [_searchBar valueForKey:@"_searchField"];
// Change search bar text color
searchField.textColor = [UIColor whiteColor];
// Change the search bar placeholder text color
[searchField setValue:[UIColor grayTextColor] forKeyPath:@"_placeholderLabel.textColor"];
if(__gSystemVersion >= 7){
_searchBar.searchBarStyle = UISearchBarStyleDefault;
}
searchBar.backgroundColor = bgColor;
UIView *topView = searchBar;
if (__gSystemVersion >= 7.0) {
topView = [[searchBar subviews] objectAtIndex:0];
searchBar.barTintColor = [UIColor clearColor];
}
//隐藏searchBar的默认背景
for (UIView *subView in topView.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subView removeFromSuperview];
break;
}
}
本文介绍如何通过代码修改UISearchBar的样式,包括调整字体颜色、背景颜色等,适用于iOS应用开发中搜索框的个性化需求。
882

被折叠的 条评论
为什么被折叠?



