[英]How to make searchbar corner round
I am trying to make searchBar
corner rounded. 我试图让
searchBar
角落圆润。 I have tried many ways of using layer.cornerRadius
, maskToBound = true
. 我尝试了很多使用
layer.cornerRadius
, maskToBound = true
。 I am loading the searchBar
in the navigationBar
programmatically. 我正在以
searchBar
在navigationBar
加载searchBar
。 I have tried many solution given on stack-overflow but nothing worked. 我已经尝试了很多关于堆栈溢出的解决方案,但没有任何效果。
func setupsearchbar()
{
// Setup the Search Controller
searchcontroller.searchResultsUpdater = self as? UISearchResultsUpdating
searchcontroller.hidesNavigationBarDuringPresentation = false
searchcontroller.searchBar.placeholder = "Search"
self.navigationItem.titleView = searchcontroller.searchBar
self.searchcontroller.searchBar.layer.cornerRadius = 30
self.searchcontroller.searchBar.layer.masksToBounds = true
definesPresentationContext = true
searchcontroller.searchBar.delegate = self
}
Please help if there is anything I can do. 如果有什么我能做的,请帮忙。
Use following code which are working fine for me in my current project. 在我当前的项目中使用以下代码对我来说很好。
if let textfield = searchController.searchBar.value(forKey: "searchField") as? UITextField {
textfield.textColor = UIColor.blue
if let backgroundview = textfield.subviews.first {
// Background color
backgroundview.backgroundColor = UIColor.white
// Rounded corner
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
I hope this will help you. 我希望这能帮到您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.