gpt4 book ai didi

ios - 为什么 UITextField 不允许我添加边框颜色?

转载 作者:可可西里 更新时间:2023-11-01 00:38:29 26 4
gpt4 key购买 nike

我有下面的方法,它应该向 uitextfield 添加边框颜色,但由于某种原因,它没有添加边框颜色,尽管它确实成功地添加到可以输入的 View 中。

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

最佳答案

搜索字段 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)
}

关于ios - 为什么 UITextField 不允许我添加边框颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56657646/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com