UISearchBar背景的处理

来源:互联网 发布:2017年大数据产业规模 编辑:程序博客网 时间:2024/06/05 05:02

1、去掉 UISearchBar 的背景
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
或者 
for (UIView *subview in searchBar.subviews)   
{    
   if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])         
   {
 [subview removeFromSuperview];    
 break;  
   }   
}

2、修改 UISearchBar 的背景
UIView *segment = [searchBar.subviews objectAtIndex:0];
UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.jpg"]];
[segment addSubview: bgImage];

3、在 tableview 上添加 UISearchBar
//动态添加 TableView
UITableView *tableView = 
[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-40) style:UITableViewStylePlain];          
tableView.backgroundColor = [UIColor whiteColor];          
tableView.delegate=self;
tableView.dataSource=self;          
[tableView setRowHeight:40];
//动态添加 SearchBar
UISearchBar searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 40)];      
searchBar.placeholder=@"Enter Name";          
searchBar.delegate = self;
tableView.tableHeaderView = searchBar;          
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;          
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;         
[searchBar release];
[self.view addSubview:tableView];       
[tableView release];

4、实现 UISearchBarDelegate 来完成 UISearchBar 的功能性部分




转载自:http://blog.csdn.net/ajrm0925/article/details/7476692


0 0
原创粉丝点击