Skip to content

Commit

Permalink
Merge pull request FluidGroup#51 from mlight3/master
Browse files Browse the repository at this point in the history
Add support for attributedText
  • Loading branch information
muukii authored May 23, 2017
2 parents b464a04 + b1fb319 commit 5cd840c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
13 changes: 8 additions & 5 deletions NextGrowingTextView/NextGrowingInternalTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ internal class NextGrowingInternalTextView: UITextView {
updatePlaceholder()
}
}

override var attributedText: NSAttributedString! {
didSet {
didChange()
updatePlaceholder()
}
}

var placeholderAttributedText: NSAttributedString? {
didSet {
Expand All @@ -64,12 +71,9 @@ internal class NextGrowingInternalTextView: UITextView {
}

override func draw(_ rect: CGRect) {

super.draw(rect)

guard displayPlaceholder == true else {
return
}
guard displayPlaceholder else { return }

let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = textAlignment
Expand All @@ -96,7 +100,6 @@ internal class NextGrowingInternalTextView: UITextView {
}

private dynamic func textDidChangeNotification(_ notification: Notification) {

updatePlaceholder()
didChange()
}
Expand Down
14 changes: 5 additions & 9 deletions NextGrowingTextView/NextGrowingTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ open class NextGrowingTextView: UIScrollView {
return _maxNumberOfLines
}
set {

guard newValue > 1 else {
_maxHeight = 1
return
Expand Down Expand Up @@ -139,10 +138,9 @@ open class NextGrowingTextView: UIScrollView {

open override func layoutSubviews() {
super.layoutSubviews()
if _previousFrame.width != bounds.width {
_previousFrame = frame
fitToScrollView()
}
guard _previousFrame.width != bounds.width else { return }
_previousFrame = frame
fitToScrollView()
}

// MARK: UIResponder
Expand Down Expand Up @@ -217,10 +215,8 @@ open class NextGrowingTextView: UIScrollView {
}

private func scrollToBottom() {
if !disableAutomaticScrollToBottom {
let offset = contentOffset
contentOffset = CGPoint(x: offset.x, y: contentSize.height - frame.height)
}
guard !disableAutomaticScrollToBottom else { return }
contentOffset.y = contentSize.height - frame.height
}

private func updateMinimumAndMaximumHeight() {
Expand Down

0 comments on commit 5cd840c

Please sign in to comment.