0

컨트롤러의 제목 대신 uisearchbar를 추가하고 싶습니다.UINavigationBar : SearchBar를 TitleView로 추가

현재 2 가지 문제가 있습니다.

1) 회색 배경이 어디에서 나올지 모르겠다. 이 사진을 확인하십시오. enter image description here

2) 다른 내부 화면에도이 검색 바가 필요합니다. 그러나 다른 컨트롤러를 밀면이 검색 바가 제거됩니다.

여기 내 코드입니다 : 여기

// Seachbar Container View 
    let searchBarContainer = ERView(frame: CGRectMake(0,0,280,44)) 
    searchBarContainer.autoresizingMask = [.FlexibleWidth] 
    searchBarContainer.backgroundColor = UIColor.clearColor() 

// Search Bar 
    let searchBar = ERSearchBar(frame: searchBarContainer.bounds) 
    searchBarContainer.addSubview(searchBar) 

// Add View as Title View in Navigation Bar 
    self.navigationController!.navigationBar.topItem?.titleView = searchBarContainer 

이의 코드 내 UISearchBar 클래스

func commonInit() -> Void { 
    // Update UI 

    if let searchField = self.valueForKey("searchField") as? UITextField{ 
     // To change background color 
     searchField.backgroundColor = UIColor.appNavigationBarDarkRedColor() 

     // Tint Color 
     if let leftViewRef = searchField.leftView { 
      leftViewRef.tintColor = UIColor.whiteColor() 
     }else if let imgLeftView = searchField.leftView as? UIImageView{ 
      imgLeftView.tintColor = UIColor.whiteColor() 
     } 

     // Font Color 
     searchField.font = UIFont.robotoRegularFont(WithSize: 14.0) 

     // Text Color 
     searchField.textColor = UIColor.whiteColor() 

     // PlaceHolder Attributes 
     searchField.attributedPlaceholder = NSAttributedString(string: "Search", attributes: [NSForegroundColorAttributeName:UIColor.whiteColor()]) 
    } 

    self.setImage(UIImage(named: "ic_search_white"), forSearchBarIcon: UISearchBarIcon.Search, state: UIControlState.Normal) 
    // To change placeholder text color 
} 

사람이 여기 제발 도와주세요.

답변

0

1) searchBarStyle 속성을 minimal로 설정하십시오. UIsearchBar에는 기본 배경색이 없습니다.

2) "내부 화면"이 무슨 뜻인지 잘 모르겠습니다. 그러나 원하는 경우 다른보기 컨트롤러에서 작동 할 수있는 검색 창 UISearchController가 당신이 찾고있는 것입니다. Apple 샘플 코드를 유용하게 사용할 수 있습니다. here

관련 문제