繁体   English   中英

如何使搜索栏转角

[英]How to make searchbar corner round

我试图让searchBar角落圆润。 我尝试了很多使用layer.cornerRadiusmaskToBound = true 我正在以searchBarnavigationBar加载searchBar 我已经尝试了很多关于堆栈溢出的解决方案,但没有任何效果。

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
}

如果有什么我能做的,请帮忙。

在我当前的项目中使用以下代码对我来说很好。

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;
    }
}

我希望这能帮到您。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM