2016-10-12 3 views
0

please see my screen shot i need thisthis is the previous output before adding image 탐색 제목 아래 검색 막대가 프로그래밍 방식으로 또는 스토리 보드를 통해 수행하는 방법이 필요합니다.탐색 제목 아래에 검색 창을 추가하는 방법

UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,30, 250,44)]; 
searchBar.placeholder = @"Search"; 
UIBarButtonItem *searchBarItem = [[UIBarButtonItem alloc]initWithCustomView:searchBar]; 
searchBarItem.tag = 123; 
searchBarItem.customView.hidden = YES; 
searchBarItem.customView.alpha = 0.0f; 
self.navigationItem.leftBarButtonItem = searchBarItem; 
self.navigationItem.title = @"locations"; 
+0

가 일부 화면이 유 –

+0

무슨 문제가 당신을 필요로 어떻게 총을 표시 할 수 있습니다 .. viewcontroller.m에 가서 다음 코드

이제

-(void)textFieldDidChange:(UITextField *)textField { searchTextString=textField.text; [self updateSearchArray:searchTextString]; } -(void)updateSearchArray:(NSString *)searchText { if(searchText.length==0) { isFilter=NO; } else { isFilter=YES; searchArray=[[NSMutableArray alloc]init]; for(NSString *string in responceArray) { NSRange stringRange = [[NSString stringWithFormat:@"%@",string] rangeOfString:searchtext.text options:NSCaseInsensitiveSearch]; if (stringRange.location != NSNotFound) { [searchArray addObject:string]; } } [jobsTable reloadData]; } }

가 잘 작동 붙여 넣기 얼굴? 일부 화면으로 알려주십시오. –

+0

네비게이션 바 안의 네비게이션 바 또는 내비게이션 바 아래쪽 –

답변

2

당신은 그것을 볼 수없는 이유를 UIBarButtonItem로, 이잖아 검색 창을 추가했습니다.

당신은 탐색의 제목 대신에 탐색 모음을 표시 탐색 모음 사용이 코드

코드의 제목보기 대신에 검색 창을 표시하려면 :

UISearchBar *searchBar = [[UISearchBar alloc]init]; 
searchBar.tintColor = [UIColor grayColor]; 
searchBar.backgroundColor = [UIColor redColor]; 
searchBar.placeholder = @"Search"; 
self.navigationItem.titleView = searchBar; 

출력 :에

enter image description here

코드 탐색 표시 줄 아래에 표시 탐색 모음 :

UISearchBar *searchBar1 = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 64)]; 
searchBar1.tintColor = [UIColor grayColor]; 
searchBar1.backgroundColor = [UIColor redColor]; 
searchBar1.placeholder = @"Search"; 
[self.view addSubview:searchBar1]; 

UPDATE :

self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 
searchBar1.searchBarStyle = UISearchBarStyleMinimal; 

UISearchBar *searchBar1 = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 64)]; 
searchBar1.tintColor = [UIColor grayColor]; 
searchBar1.searchBarStyle = UISearchBarStyleMinimal; 
searchBar1.backgroundColor = [UIColor redColor]; 
searchBar1.placeholder = @"Search"; 
[self.view addSubview:searchBar1]; 

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; 

출력 :

enter image description here

업데이트 출력

가 텍스트 필드를 사용자 정의하려면 :

UISearchBar *searchBar1 = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 64)]; 
searchBar1.tintColor = [UIColor grayColor]; 
searchBar1.searchBarStyle = UISearchBarStyleMinimal; 
searchBar1.backgroundColor = [UIColor redColor]; 
searchBar1.placeholder = @"Search"; 
[self.view addSubview:searchBar1]; 

[searchBar1 setSearchFieldBackgroundImage:[UIImage imageNamed:@"text-input.png"] forState:UIControlStateNormal]; 

이미지는 검색 창의 텍스트 필드와 같이 높이가 30 픽셀입니다.

enter image description here

그리고 출력 : 여기

은 이미지입니다

enter image description here 는 희망이 도움이 ...

해피 코딩 ...

updated output

+0

은 잘 작동합니다. 하지만 어떻게 할 탐색기 및 검색 바에 대한 배경색을 설정해야합니다. – ios

+0

이 코드를 사용하여 탐색 모음을 빨간색으로 표시 할 수 있습니다. self.navigationController.navigationBar.barTintColor = [UIColor redColor]; – Janmenjaya

+0

이 코드는 탐색 컨트롤러의 색만 변경합니다. 하지만 내비게이션 컨트롤러 내부에서 검색을 설정해야하며보기 아래에 제목이 없어야합니다. – ios

0

우리는 또한 StoryBoard에, 내 응용 프로그램에서 잘 작동, 검색 창으로

이동을 텍스트 상자를 사용하고 다음은 storyboard에 반대 Library--> type view 드래그에서

을 변경 할 수 및 탐색 표시 줄 아래에 붙여 넣을 수 있습니다.

텍스트 상자를보기에 추가하고 콘센트 및 대리자를 할당하십시오.

지금