Ios 如何在Swift3中的UISearchBar上设置边框底部

Ios 如何在Swift3中的UISearchBar上设置边框底部,ios,swift,uisearchbar,border-color,Ios,Swift,Uisearchbar,Border Color,我想指定UISearchBar的底部边框颜色。我已经看到了很多有助于去除边框的答案,或者作为一个整体设置边框颜色,但是我只想为底部边框设置边框颜色。这是我的密码: searchController.searchBar.layer.borderWidth=1 searchController.searchBar.layer.borderColor=UIColor.white.cgColor 有没有办法只为底部边框设置borderColor?如果您使用的是3以下的swift版本(只需向文本字段添加一

我想指定UISearchBar的底部边框颜色。我已经看到了很多有助于去除边框的答案,或者作为一个整体设置边框颜色,但是我只想为底部边框设置边框颜色。这是我的密码:

searchController.searchBar.layer.borderWidth=1
searchController.searchBar.layer.borderColor=UIColor.white.cgColor


有没有办法只为底部边框设置borderColor?

如果您使用的是3以下的swift版本(只需向文本字段添加一个子视图,如下所示

let frame = CGRectMake(0, textField.frame.size.height - 1, textField.frame.size.width, 1)
let border = UIView(frame: frame)
border.backgroundColor = UIColor.whiteColor()
textField.addSubview(border)

您可以添加高度为1pt的视图作为UISearchBar的子视图。这对您很有用。这对我很有用!谢谢@AdeelMirajYou。很高兴提供帮助:)。我已经用代码回答了这个问题,以供参考。