@@ -31,17 +31,16 @@ internal class NextGrowingInternalTextView: UITextView {
3131
3232 var didChange : ( ) -> Void = { }
3333 var didUpdateHeightDependencies : ( ) -> Void = { }
34-
34+
3535 private lazy var placeholderDisplayLabel = UILabel ( )
3636
3737 override init ( frame: CGRect , textContainer: NSTextContainer ? ) {
3838 super. init ( frame: frame, textContainer: textContainer)
3939
4040 NotificationCenter . default. addObserver ( self , selector: #selector( NextGrowingInternalTextView . textDidChangeNotification ( _ : ) ) , name: UITextView . textDidChangeNotification, object: self )
41-
42- placeholderDisplayLabel. numberOfLines = 0
43- placeholderDisplayLabel. adjustsFontSizeToFitWidth = true
41+ isPlaceHolderMultiLine = false
4442 placeholderDisplayLabel. minimumScaleFactor = 0.4
43+ placeholderDisplayLabel. lineBreakMode = . byWordWrapping
4544 addSubview ( placeholderDisplayLabel)
4645 }
4746
@@ -78,7 +77,23 @@ internal class NextGrowingInternalTextView: UITextView {
7877 didUpdateHeightDependencies ( )
7978 }
8079 }
81-
80+
81+ var isPlaceHolderMultiLine : Bool {
82+ get {
83+ placeholderDisplayLabel. numberOfLines != 1
84+ }
85+ set {
86+ if newValue {
87+ placeholderDisplayLabel. numberOfLines = 1
88+ placeholderDisplayLabel. adjustsFontSizeToFitWidth = true
89+ } else {
90+ placeholderDisplayLabel. numberOfLines = 0
91+ placeholderDisplayLabel. adjustsFontSizeToFitWidth = false
92+ }
93+ updatePlaceholder ( )
94+ }
95+ }
96+
8297 var placeholderAttributedText : NSAttributedString ? {
8398 get {
8499 placeholderDisplayLabel. attributedText
@@ -92,19 +107,18 @@ internal class NextGrowingInternalTextView: UITextView {
92107 override func layoutSubviews( ) {
93108 super. layoutSubviews ( )
94109
95- let maxSize = bounds. inset ( by: textContainerInset) . size
96-
97- var size = placeholderDisplayLabel . sizeThatFits ( maxSize )
98- size. height = min ( size . height, maxSize . height)
99-
110+ let boundsInsettedSize = bounds. inset ( by: textContainerInset) . size
111+ var size = placeholderDisplayLabel . sizeThatFits ( boundsInsettedSize )
112+ if !isPlaceHolderMultiLine {
113+ size. height = min ( boundsInsettedSize . height, size . height)
114+ }
100115 placeholderDisplayLabel. frame = CGRect (
101116 origin: . init(
102117 x: 5 + textContainerInset. left,
103118 y: textContainerInset. top
104119 ) ,
105120 size: size
106121 )
107-
108122 }
109123
110124 // MARK: Private
0 commit comments