Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attributed placeholder fixes #39 #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 14 additions & 2 deletions KMPlaceholderTextView/KMPlaceholderTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -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
Expand Down