【发布时间】:2018-06-04 04:54:42
【问题描述】:
我在导航控制器上以编程方式更改搜索栏设计时遇到问题。我只想制作如下图所示的搜索栏曲线:
我在堆栈溢出中尝试了很多示例,但我仍然未能更改形状。这是现在的样子:
这里是源代码,关于已经做过的事情:
//MARK for searchBar UI
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.placeholder = " Search for programs..."
searchController.searchBar.sizeToFit()
searchController.searchBar.isTranslucent = false
searchController.searchBar.backgroundImage = UIImage()
searchController.searchBar.delegate = self
navigationItem.titleView = searchController.searchBar
self.searchController.searchBar.layer.cornerRadius = 20.0
self.searchController.searchBar.clipsToBounds = true
// SearchBar text
let textFieldInsideUISearchBar = searchController.searchBar.value(forKey: "searchField") as? UITextField
textFieldInsideUISearchBar?.borderStyle = .roundedRect
textFieldInsideUISearchBar?.font = textFieldInsideUISearchBar?.font?.withSize(14)
现在,我真的不知道如何更改它,提前谢谢。
【问题讨论】:
-
你可以试试stackoverflow.com/a/49810660/4601900和试试
searchBarContainerheight -
尝试增加
searchBar.layer.cornerRadius值 -
@PPL 抱歉,我试过了。但还是失败了
-
self.searchController.searchBar.layer.cornerRadius = self.searchController.searchBar.frame.height/2.0
标签: swift uisearchbar uinavigationitem uisearchcontroller programmatically