标签:uisearchbar 背景色
1. 使用此代码改变搜索栏“UITextField
将backgroundImage
UITextField *searchField;
NSUInteger numViews = [searchBar.subviews count];
for(int i = 0; i < numViews; i++) {
if([[searchBar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { //conform?
searchField = [searchBar.subviews objectAtIndex:i];
}
}
if(!(searchField == nil)) {
searchField.textColor = [UIColor whiteColor];
[searchField setBackground: [UIImage imageNamed:@"yourImage"]];//just add here gray image which you display in quetion
[searchField setBorderStyle:UITextBorderStyleNone];
}
该波纹管代码的变化UISearchBarIcon
UIImageView *searchIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourSearchBarIconImage"]];
searchIcon.frame = CGRectMake(10, 10, 24, 24);
[searchBar addSubview:searchIcon];
[searchIcon release];
也为改变searcBar图标搜索栏的你哪些可用的iOS 5 +
- (void)setImage:(UIImage *)iconImage forSearchBarIcon:(UISearchBarIcon)icon state:(UIControlState)state
在这里你可以设置4种UISearchBarIcon
即UISearchBarIconBookmark
UISearchBarIconClear
UISearchBarIconResultsList
UISearchBarIconSearch
我希望这可以帮助您... - (void)setSearchFieldBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state
用例:
[mySearchBar setSearchFieldBackgroundImage:myImage forState:UIControlStateNormal];
可悲的是,在iOS 4的你需要恢复到较少见其他的答案。 UITextField *txfSearchField = [_searchBar valueForKey:@"_searchField"];
txfSearchField.backgroundColor = [UIColor redColor];
这样,您就不需要创建一个图像,它的大小,等.. searchBar.tintColor = [UIColor redColor];
为应用背景图像:
[self.searchBar setSearchFieldBackgroundImage:
[UIImage imageNamed:@"Searchbox.png"]
forState:UIControlStateNormal];
for (UIView* subview in [[self.searchBar.subviews lastObject] subviews]) {
if ([subview isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField*)subview;
[textField setBackgroundColor:[UIColor redColor]];
}
}
标签:uisearchbar 背景色
原文地址:http://blog.csdn.net/baron_blogs/article/details/42964687