Is there any way to set the active border color and inactive border color to UITextView? For example, if textview is focused to input text, then border color will be red, otherwise textview border color set to gray. Thank you.
One way would be to implement textViewDidBeginEditing(_:)
and textViewDidEndEditing(_:)
from UITextViewDelegate
in your class where you want to change borderColor
property:
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With