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

标签 ios swift colors uisearchbar

我想指定 UISearchBar 的底部边框颜色。我已经看到很多答案,这些答案将有助于摆脱边框,或设置整体边框颜色,但我只想设置底部边框的边框颜色。这是我的代码:

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

有没有办法设置底部边框的边框颜色?

最佳答案

只需向文本字段添加一个 subview ,如下所示

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)

关于ios - 如何在 Swift3 中的 UISearchBar 上设置边框底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39859742/

相关文章:

ios - 可以在 Xamarin Test Cloud 中启用 iPhone 设备密码吗?

ios - 无法发出预编译 header ,因为循环条件

ios - 当我用颜色部分填充 TableView 单元格时单元格中的文本出现问题

android - 如何在 opengl 2.0 中的对象上绘制线框?

math - 如何使用按位运算符使 ARGB 透明

ios - SwiftUI 和三指撤消手势

ios - 当我在 Swift 中将对象的委托(delegate)设置为 "self"时,编译器在做什么?

ios - 在 IOS 中使用 DatePicker 而不是键盘的两个单独的文本字段

ios - 更改拉动刷新事件指示器

swift - 如何使枚举符合 Swift 中的协议(protocol)?