diff --git a/Example/ViewController.swift b/Example/ViewController.swift index fbf9df2..78f9464 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -15,6 +15,17 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() + + + let attributes = [ + NSFontAttributeName : UIFont.boldSystemFont(ofSize: 14), + NSForegroundColorAttributeName : UIColor.black, + NSBackgroundColorAttributeName: UIColor.groupTableViewBackground, + NSStrokeWidthAttributeName : 3.0, + ] as [String : Any] + + let placeholder = NSAttributedString(string: "NSAttributedString NSAttributedString NSAttributedString NSAttributedString \nNSAttributedString NSAttributedString NSAttributedString NSAttributedString \nNSAttributedString NSAttributedString NSAttributedString NSAttributedString \n", attributes: attributes) + placeholderTextView.attributedPlaceholder = placeholder } override func viewWillAppear(_ animated: Bool) { diff --git a/KMPlaceholderTextView/KMPlaceholderTextView.swift b/KMPlaceholderTextView/KMPlaceholderTextView.swift index 704800d..7207335 100644 --- a/KMPlaceholderTextView/KMPlaceholderTextView.swift +++ b/KMPlaceholderTextView/KMPlaceholderTextView.swift @@ -33,9 +33,17 @@ open class KMPlaceholderTextView: UITextView { private var placeholderLabelConstraints = [NSLayoutConstraint]() + open var attributedPlaceholder: NSAttributedString? { + didSet { + placeholderLabel.attributedText = attributedPlaceholder + } + } + @IBInspectable open var placeholder: String = "" { didSet { - placeholderLabel.text = placeholder + if attributedPlaceholder == nil{ + placeholderLabel.text = placeholder + } } } @@ -103,7 +111,11 @@ open class KMPlaceholderTextView: UITextView { placeholderLabel.font = font placeholderLabel.textColor = placeholderColor placeholderLabel.textAlignment = textAlignment - placeholderLabel.text = placeholder + if let attributedPlaceholder = attributedPlaceholder{ + placeholderLabel.attributedText = attributedPlaceholder + }else{ + placeholderLabel.text = placeholder + } placeholderLabel.numberOfLines = 0 placeholderLabel.backgroundColor = UIColor.clear placeholderLabel.translatesAutoresizingMaskIntoConstraints = false