seachBar=[[UISearchBar alloc] init];
//修改搜索框背景
seachBar.backgroundColor=[UIColor clearColor];
//去掉搜索框背景
//1.
[[searchbar.subviews objectAtIndex:0]removeFromSuperview];
//2.
for (UIView *subview in seachBar.subviews)
{
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}
//3自定义背景
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"40-di.png"]];
[mySearchBar insertSubview:imageView atIndex:1];
[imageView release];
//4输入搜索文字时隐藏搜索按钮,清空时显示
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
searchBar.showsScopeBar = YES;
[searchBar sizeToFit];
[searchBar setShowsCancelButton:YES animated:YES];
return YES;
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
searchBar.showsScopeBar = NO;
[searchBar sizeToFit];
[searchBar setShowsCancelButton:NO animated:YES];
return YES;
}
//改变搜索按钮文字
//改变UISearchBar取消按钮字体
for(id cc in [searchBar subviews])
{
if([cc isKindOfClass:[UIButton class]])
{
UIButton *btn = (UIButton *)cc;
[btn setTitle:@"搜索" forState:UIControlStateNormal];
}
}
分享到:
相关推荐
今天用到UISearchBar,之前网上提供的方法已经不能有效的去除掉它的背景色了,修改背景色方法如下: mySearchBar.backgroundColor = RGBACOLOR(249,249,249,1); mySearchBar.backgroundImage = [self ...
UISearchBar使用Demo,UISearchBar使用Demo,UISearchBar使用Demo
通过UItextField自定义UISearchBar 描述了UItextField代理的来实现uisearchbar功能
uisearchbar 使用指南
iOS搜索。 iOS-UISearchBar
UISearchBar 修改占位符的放大镜,修改cancal,修改占位符。
UISearchBar
search bar
UISearchBar的一个基本重新实现更容易的主题更换和更好的动画
UISearchBar扩展类,可以实现点击完成收回键盘,只需导入项目,在需要的时候引入头文件即可,使用非常简单
在UINavigationBar上显示UISearchBar, 并实现UISearchDisplayController功能的小Demo, 更多讲解在http://www.cnblogs.com/sely-ios/p/Sely.html
UISearchBar 不同样式的搜索框,代码简单
1、修改UISearchBar的背景颜色 UISearchBar是由两个subView组成的,一个是UISearchBarBackGround,另一个是UITextField. 要IB中没有直接操作背景的属性。方法是直接将 UISearchBarBackGround移去 seachBar=[...
理论:http://blog.csdn.net/z251257144/article/details/7580307
UISearchBarTest. UISearchBar搜索栏示例程序v
实现UISearchBar的搜索功能,对于模糊搜索做的小demo.
iOS开发套件中自带的UISearchBar搜索框我们平时经常可以用到,我们可以在默认的基础上修改文字颜色、背景颜色和背景图片等,这里我们稍微总结一下iOS中的UISearchBar搜索框组件基础使用指南.