2017-09-01 3 views
1

Swift 3を使用してデバイス上でテストすると、黒色/灰色の境界線を削除する必要があるが削除されないコードを試しました。変わったことは境界があることですが、searchBarをタイプする準備ができたら、境界線はビューが再びロードされるまでそこにはありません。したがって、searchBarをクリックするまで、境界線が表示されます。Swift:SearchBarの黒色/灰色の境界線がクリックされるまで消えない

これは私のコードです:

// Coloring TableView 
myTableView.backgroundColor = UIColor.white 
myTableView.sectionIndexBackgroundColor = UIColor.black 
myTableView.sectionIndexColor = UIColor.black 

// Search Bar 
searchController.searchBar.backgroundColor = UIColor.white 
searchController.searchBar.barTintColor = UIColor.white 

// Coloring SearchBar Cancel button 
let cancelButtonAttributes: NSDictionary = [NSForegroundColorAttributeName: UIColor.black] 
UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes as? [String : AnyObject], for: UIControlState.normal) 

// Scope: Selected text 
let titleTextAttributesSelected = [NSForegroundColorAttributeName: UIColor.white] 
UISegmentedControl.appearance().setTitleTextAttributes(titleTextAttributesSelected, for: .selected) 

// Scope: Normal text 
let titleTextAttributesNormal = [NSForegroundColorAttributeName: UIColor.black] 
UISegmentedControl.appearance().setTitleTextAttributes(titleTextAttributesNormal, for: .normal) 

// Coloring Scope Bar 
UISegmentedControl.appearance().tintColor = UIColor.black 
UISegmentedControl.appearance().backgroundColor = UIColor.white 

// Search Bar 
searchController.searchResultsUpdater = self 
searchController.dimsBackgroundDuringPresentation = false 
definesPresentationContext = true 
myTableView.tableHeaderView = searchController.searchBar 

// Scope Bar 
searchController.searchBar.scopeButtonTitles = ["All", "Released", "Unreleased", "Open Beta"] 
searchController.searchBar.delegate = self 

let searchController = UISearchController(searchResultsController: nil) 

// SEARCH BAR: Filtering Content 
func filterContentForSearchText(searchText: String, scope: String = "All") { 

    filteredFollowedArray = followedArray.filter { Blog in 

     let categoryMatch = (scope == "All") || (Blog.blogType == scope) 

     return categoryMatch && (Blog.blogName.lowercased().contains(searchText.lowercased())) 
    } 

    filteredBlogArray = blogArray.filter { Blog in 

     let categoryMatch = (scope == "All") || (Blog.blogType == scope) 

     return categoryMatch && (Blog.blogName.lowercased().contains(searchText.lowercased())) 
    } 

    myTableView.reloadData() 
} 

// SEARCH BAR: Updating Results 
func updateSearchResults(for searchController: UISearchController) { 

    filterContentForSearchText(searchText: searchController.searchBar.text!) 
} 

func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {} 

func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {} 

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {} 

// SEARCH BAR: Scope 
func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) { 

    filterContentForSearchText(searchText: searchBar.text!, scope: searchBar.scopeButtonTitles![selectedScope]) 
} 

// SEARCH BAR: Updating Scope 
func updateSearchResultsForSearchController(searchController: UISearchController) { 

    let searchBar = searchController.searchBar 
    let scope = searchBar.scopeButtonTitles![searchBar.selectedScopeButtonIndex] 

    filterContentForSearchText(searchText: searchController.searchBar.text!, scope: scope) 
} 

// Deallocating Search Bar 
deinit{ 
    if let superView = searchController.view.superview { 
     superView.removeFromSuperview() 
    } 
} 

これは、検索バーは、ビューが最初にロードされたときに、一番上の行が灰色でどのように見えるかである(灰色のは、あなたが、とても色あせに見えるなぜここで私はしないでくださいそれが、灰色の非常に細い線がある)を見ることができない。

pic1

、あなたが検索バーをクリックした後、行が黒くなる:

pic2

そして私は私に呼ばれたこのコードを追加するとき、これは起こる:

// Search Bar Border 
let searchBar = searchController.searchBar 
searchBar.backgroundImage = UIImage() 

pic3

、これは私がそのコードで検索バーをクリックした後で、どのように見えるようになっています。枠なし:

pic4

答えて

0

あなただけの小さなサイズのシミュレータで、この動作を確認していますか? 2番目のスクリーンショットの黒い線は、最初のスクリーンショットの検索バーに接続されていません。代わりにステータスバーの下部に似ています。時にはシミュレータが細線を正しく表示できないことがあります。シミュレータのサイズを最大またはそれ以上に増やし、電話でテストします。

+0

これは私のデバイス上にあるすべてのiPhone 6s – BroSimple

関連する問題