我有以下方法,应该将边框颜色添加到uitextfield中,但是由于某种原因,它没有添加边框颜色,尽管它确实成功添加到了可以键入的视图中。
func setupSearchBar() {
searchField.frame = CGRect(x: 4, y: 6.5, width: 366.58, height: 42)
searchField.layer.cornerRadius = searchField.frame.height/2
topBackgroundView.layer.borderWidth = 0.35
searchField.layer.borderColor = UIColor(red: 0/225, green: 0/225, blue: 0/225, alpha: 0.49).cgColor
searchField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
view.addSubview(searchField)
}
答案 0 :(得分:4)
搜索字段borderWidth默认为0。尝试:
func setupSearchBar() {
searchField.frame = CGRect(x: 4, y: 6.5, width: 366.58, height: 42)
searchField.layer.cornerRadius = searchField.frame.height/2
topBackgroundView.layer.borderWidth = 0.35
searchField.layer.borderColor = UIColor(red: 0/225, green: 0/225, blue: 0/225, alpha: 0.49).cgColor
searchField.layer.borderWidth = 1.0 // <- Add here
searchField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
view.addSubview(searchField)
}