How to set UITextView Placeholder in swift 4.
import UIKit
class DescribeYourselfVC: UIViewController, UITextViewDelegate {
@IBOutlet var txtDescription: UITextView!
//MARK:- View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setTheme()
// Do any additional setup after loading the view.
}
//MARK:- set Theme on ValutVC controller
func setTheme()
{
txtDescription.text = "Describe Yourself"
txtDescription.textColor = COLOR.GREY_DARK
txtDescription.font = UIFont(name: FONT_NAME.OPENSANS_REGULAR, size: FONT_SIZE.FOURTEEN)
txtDescription.layer.borderWidth = 0.01
txtDescription.layer.borderColor = UIColor.white.cgColor
txtDescription.layer.cornerRadius = 5
txtDescription.layer.masksToBounds = true
}
//MARK:- TextView Delegate methods
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if textView == txtDescription
{
self.txtDescription.textColor = COLOR.BLACK
}
return true
}
func textViewDidEndEditing(_ textView: UITextView) {
if txtDescription.text.length > 0 {
} else {
txtDescription.text = "Describe Yourself"
txtDescription.textColor = COLOR.GREY_DARK
}
}
func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
if textView.text == "Describe Yourself" {
txtDescription.textColor = COLOR.BLACK
txtDescription.text = ""
}
return true
}
}
Comments
Post a Comment