@@ -9,13 +9,17 @@ import Foundation
99import UIKit
1010import ARMarkdownTextStorage
1111
12- public class ARGrowingTextView : UIView {
12+ open class ARGrowingTextView : UIView {
1313 public weak var delegate : ARGrowingTextViewDelegate ?
1414
1515 // MARK: Views
1616 public private( set) var internalTextView = ARTextViewInternalTextStyle ( frame: . zero)
1717 // Constraints
1818 private var textViewHeightConstraint : NSLayoutConstraint !
19+ private var textViewTopConstraint : NSLayoutConstraint !
20+ private var textViewBottomConstraint : NSLayoutConstraint !
21+ private var textViewLeadingConstraint : NSLayoutConstraint !
22+ private var textViewTrailingConstraint : NSLayoutConstraint !
1923
2024 // MARK: Properties
2125 private var sizeConfig = SizeConfig ( minHeight: 0 , maxHeight: 0 , minNumberOfLines: 1 , maxNumberOfLines: 3 )
@@ -126,11 +130,11 @@ public class ARGrowingTextView: UIView {
126130 }
127131 public var contentInset : UIEdgeInsets = . zero {
128132 didSet {
129- var textViewFrame = frame
130- textViewFrame . origin = CGPoint ( x : contentInset. left, y : contentInset . top - contentInset . bottom )
131- textViewFrame . size . width = textViewFrame . width - ( contentInset. left + contentInset . right)
132-
133- internalTextView . frame = textViewFrame
133+ textViewTopConstraint ? . constant = contentInset . top
134+ textViewLeadingConstraint ? . constant = contentInset. left
135+ textViewTrailingConstraint . constant = contentInset. right
136+ textViewBottomConstraint ? . constant = contentInset . bottom
137+ layoutIfNeeded ( )
134138
135139 recalculateMinAndMaxHeights ( )
136140 }
@@ -163,7 +167,7 @@ public class ARGrowingTextView: UIView {
163167
164168 // MARK: Initialization
165169 // having initwithcoder allows us to use HPGrowingTextView in a Nib. -- aob, 9/2011
166- required init ? ( coder: NSCoder ) {
170+ required public init ? ( coder: NSCoder ) {
167171 super. init ( coder: coder)
168172 commonInitialiser ( )
169173 }
@@ -173,6 +177,11 @@ public class ARGrowingTextView: UIView {
173177 commonInitialiser ( )
174178 }
175179
180+ public init ( ) {
181+ super. init ( frame: . zero)
182+ commonInitialiser ( )
183+ }
184+
176185 public init ( frame: CGRect , textContainer: NSTextContainer ) {
177186 super. init ( frame: frame)
178187 commonInitialiser ( textContainer: textContainer)
@@ -186,16 +195,22 @@ public class ARGrowingTextView: UIView {
186195 addSubview ( internalTextView)
187196
188197 internalTextView. translatesAutoresizingMaskIntoConstraints = false
189- NSLayoutConstraint . activate ( [
190- internalTextView. topAnchor. constraint ( equalTo: topAnchor) ,
191- internalTextView. leadingAnchor. constraint ( equalTo: leadingAnchor) ,
192- internalTextView. trailingAnchor. constraint ( equalTo: trailingAnchor) ,
193- internalTextView. bottomAnchor. constraint ( equalTo: bottomAnchor)
194- ] )
195198
196199 let height = internalTextView. sizeThatFits ( internalTextView. frame. size) . height
200+
201+ textViewTopConstraint = internalTextView. topAnchor. constraint ( equalTo: topAnchor)
202+ textViewLeadingConstraint = internalTextView. leadingAnchor. constraint ( equalTo: leadingAnchor)
203+ textViewTrailingConstraint = trailingAnchor. constraint ( equalTo: internalTextView. trailingAnchor)
204+ textViewBottomConstraint = bottomAnchor. constraint ( equalTo: internalTextView. bottomAnchor)
197205 textViewHeightConstraint = internalTextView. heightAnchor. constraint ( equalToConstant: height)
198- textViewHeightConstraint. isActive = true
206+
207+ NSLayoutConstraint . activate ( [
208+ textViewTopConstraint,
209+ textViewLeadingConstraint,
210+ textViewTrailingConstraint,
211+ textViewBottomConstraint,
212+ textViewHeightConstraint
213+ ] )
199214
200215 sizeConfig. minHeight = height
201216
0 commit comments