//添加搜索框
UISearchBar *searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 280, kSearchHeight)];
[searchBar setBackgroundColor:[UIColor clearColor]];
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchBar.keyboardType = UIKeyboardTypeDefault;
searchBar.placeholder = [NSString stringWithCString:"輸入關鍵字..." encoding: NSUTF8StringEncoding];
searchBar.showsCancelButton = YES;
searchBar.delegate = self;
searchBar.tag = 100;
searchBar.showsCancelButton = NO;//是否顯示取消按鈕
//5.0之前,添加背景-----刪除searchBar的背景視圖
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass: NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}