@@ -33,6 +33,12 @@ open class NextGrowingTextView: UIView {
3333 /// Hides typed text one or more.
3434 case onTypedText
3535 }
36+
37+ public enum PlaceholderHorizontalLayout {
38+ case leading
39+ case center
40+ case trailing
41+ }
3642
3743 public var minLines : Int
3844 public var maxLines : Int
@@ -41,16 +47,19 @@ open class NextGrowingTextView: UIView {
4147 public var isFlashScrollIndicatorsEnabled : Bool = false
4248
4349 public var placeholderHidingMode : PlaceholderHidingMode
50+ public var placeholderHorizontalLayout : PlaceholderHorizontalLayout
4451
4552 public init (
4653 placeholderHidingMode: PlaceholderHidingMode = . onTypedText,
54+ placeholderHorizontalLayout: PlaceholderHorizontalLayout = . leading,
4755 minLines: Int = 1 ,
4856 maxLines: Int = 3 ,
4957 isAutomaticScrollToBottomEnabled: Bool = true ,
5058 isFlashScrollIndicatorsEnabled: Bool = false
5159 ) {
5260
5361 self . placeholderHidingMode = placeholderHidingMode
62+ self . placeholderHorizontalLayout = placeholderHorizontalLayout
5463 self . minLines = minLines
5564 self . maxLines = maxLines
5665 self . isAutomaticScrollToBottomEnabled = isAutomaticScrollToBottomEnabled
@@ -163,12 +172,27 @@ open class NextGrowingTextView: UIView {
163172 NSLayoutConstraint . activate ( [
164173
165174 placeholderLabel. topAnchor. constraint ( equalTo: topAnchor, constant: inset. top) ,
166- placeholderLabel. leftAnchor. constraint ( equalTo: leftAnchor, constant: inset. left + 4 ) ,
167- placeholderLabel. rightAnchor. constraint ( lessThanOrEqualTo: rightAnchor, constant: - ( inset. right + 4 ) ) ,
168175 placeholderLabel. bottomAnchor. constraint ( lessThanOrEqualTo: bottomAnchor, constant: - inset. bottom) ,
169-
176+
170177 ] )
171178
179+ switch configuration. placeholderHorizontalLayout {
180+ case . leading:
181+ NSLayoutConstraint . activate ( [
182+ placeholderLabel. leadingAnchor. constraint ( equalTo: leadingAnchor, constant: inset. left + 4 ) ,
183+ placeholderLabel. trailingAnchor. constraint ( lessThanOrEqualTo: trailingAnchor, constant: - ( inset. right + 4 ) ) ,
184+ ] )
185+ case . center:
186+ NSLayoutConstraint . activate ( [
187+ placeholderLabel. centerXAnchor. constraint ( equalTo: centerXAnchor, constant: 0 ) ,
188+ ] )
189+ case . trailing:
190+ NSLayoutConstraint . activate ( [
191+ placeholderLabel. leadingAnchor. constraint ( greaterThanOrEqualTo: leadingAnchor, constant: inset. left + 4 ) ,
192+ placeholderLabel. trailingAnchor. constraint ( equalTo: trailingAnchor, constant: - ( inset. right + 4 ) ) ,
193+ ] )
194+ }
195+
172196 // refresh with current state and new configuration
173197 update ( by: state)
174198
0 commit comments