UISearchBar

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/iukey/article/details/7318682

UISearchBar 更多的功能定製查看協議 UISearchBarDelegate 的定義。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章