我以编程方式创建了一个 UISearchBar(不是 UISearchController)并将其设置为 tableview
header 。但是,它没有出现。任何人都可能知道这是为什么?
课外:
var searchBar = UISearchBar()
在 viewDidLoad 方法中。
searchBar.barTintColor = UIColor(red:0.54, green:0.77, blue:0.80, alpha:1.0)
searchBar.placeholder = "Cauta cheltuieli"
searchBar.backgroundImage = #imageLiteral(resourceName: "searchbarback")
tableView.tableHeaderView = searchBar
tableView.setContentOffset(CGPoint.init(x: 0, y: 44), animated: true)
最佳答案
您忘记为搜索栏指定任何尺寸,因此大小将为零。
尝试通过设置框架来设置尺寸或使用带框架的构造函数。
let searchbar = UISearchBar(frame: CGRect(x: 0.0, y: 0.0, height: 50.0, width: tableView.frame.width))
关于ios - 以编程方式 UISearchBar 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47254372/