//導航條的搜索條 UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(500.0f,0.0f,250.0f,44.0f)]; searchBar.delegate = self; [searchBar setPlaceholder:@"搜索"]; //將搜索條放在一個UIView上 UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 44)]; searchView.backgroundColor = [UIColor clearColor]; [searchView addSubview:searchBar]; self.navigationItem.titleView = searchView; [searchBar release]; [searchBiew release];
或者code
UISearchBar* searchBar=[[[UISearchBar alloc]initWithFrame:CGRectMake(560, 0, 150,40)]autorelease]; //searchBar.delegate = self; [searchBar setPlaceholder:@"search"]; [self.navigationController.navigationBar addSubview:searchBar];