gpt4 book ai didi

ios - Swift:SearchBar 上的黑色/灰色边框在单击之前不会消失

转载 作者:行者123 更新时间:2023-12-01 16:23:33 25 4
gpt4 key购买 nike

使用 Swift 3 并在我的设备上进行测试,我尝试了几个应该删除黑色/灰色边框但没有被删除的代码。奇怪的是边框在那里,但是一旦我单击准备输入的 searchBar,边框就不再存在,直到再次加载 View 。所以边框只是显示,直到我单击搜索栏。

这是我的代码:

// 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()
}
}

这是第一次加载 View 时 searchBar 的外观,顶部的线是灰色的(我不明白为什么这里的灰色看起来如此褪色,你看不到它,但那里有一条非常细的灰色线):

pic1

单击搜索栏后,该行变为黑色:

pic2

当我添加引用我的这段代码时,就会发生这种情况:
// Search Bar Border
let searchBar = searchController.searchBar
searchBar.backgroundImage = UIImage()

pic3

这是在我使用该代码单击 searchBar 之后,以及它的外观。无边界:

pic4

最佳答案

您是否仅在小型模拟器中检查此行为?第二个屏幕截图中的黑线看起来与第一个屏幕截图中的搜索栏没有连接。它看起来像状态栏的底部。有时模拟器无法正确显示细线。我会将模拟器尺寸增加到最大或更好,在手机上进行测试。

关于ios - Swift:SearchBar 上的黑色/灰色边框在单击之前不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46005528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com