gpt4 book ai didi

swift - swift 3 中的 UITextView 边框

转载 作者:搜寻专家 更新时间:2023-10-31 21:56:15 26 4
gpt4 key购买 nike

有没有办法给UITextView设置active border color和inactive border color?例如,如果 textview 聚焦于输入文本,则边框颜色将为红色,否则 textview 边框颜色设置为灰色。谢谢。

最佳答案

一种方法是实现 textViewDidBeginEditing(_:)textViewDidEndEditing(_:)从您要更改 borderColor 属性的类中的 UITextViewDelegate:

class ViewController: UIViewController, UITextViewDelegate {

...

override func viewDidLoad() {
super.viewDidLoad()
self.textView.delegate = self
self.textView.layer.borderWidth = 1.0
}

func textViewDidBeginEditing(_ textView: UITextView) {
textView.layer.borderColor = UIColor.redColor.cgColor
}

func textViewDidEndEditing(_ textView: UITextView) {
textView.layer.borderColor = UIColor.clearColor.cgColor
}
}

关于swift - swift 3 中的 UITextView 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46748301/

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