說白了,就是在navigationcotroller中,顯示一個view,具體實現可參考如下代碼
CGRect mainViewBounds = self.navigationController.view.bounds; UISearchBar *customSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(CGRectGetWidth(mainViewBounds)/2-((CGRectGetWidth(mainViewBounds)-120)/2), CGRectGetMinY(mainViewBounds)+22, CGRectGetWidth(mainViewBounds)-120, 40)]; customSearchBar.delegate = self; customSearchBar.showsCancelButton = NO; customSearchBar.searchBarStyle = UISearchBarStyleMinimal; [self.navigationController.view addSubview: customSearchBar];