Skip to content

Commit

Permalink
Fixed alignment issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaguilar committed Oct 12, 2017
1 parent 00e0d03 commit 7eb6fa3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions MultilineTextField/Classes/MultilineTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public class MultilineTextField: UITextView {
}

/// Point used as the origin for displaying the left view.
public var leftViewOrigin: CGPoint = CGPoint(x: 8, y: 8) {
public var leftViewOrigin: CGPoint = CGPoint(x: 0, y: 6) {
didSet {
invalidateLeftView()
}
}

private var leftExlusionPath: UIBezierPath?
private var leftExclusionPath: UIBezierPath?


/// Convenience property to set an image directly instead of a left view
Expand Down Expand Up @@ -124,6 +124,8 @@ public class MultilineTextField: UITextView {
}

func initializeUI() {
self.textContainer.lineFragmentPadding = 0

self.insertSubview(placeholderView, at: 0)

placeholderView.frame = self.bounds
Expand Down Expand Up @@ -160,6 +162,11 @@ public class MultilineTextField: UITextView {
}
)

fieldObservations.append(
self.textContainer.observe(\.lineFragmentPadding, options: [.initial, .new]) { [weak self] (textContainer, changes) in
self?.placeholderView.textContainer.lineFragmentPadding = textContainer.lineFragmentPadding
}
)
}

@objc private func textViewDidChange(notification: Notification) {
Expand Down Expand Up @@ -188,7 +195,7 @@ public class MultilineTextField: UITextView {
}

private func invalidateLeftView() {
if let path = self.leftExlusionPath {
if let path = self.leftExclusionPath {
remove(exlusionPath: path)
}

Expand All @@ -204,8 +211,11 @@ public class MultilineTextField: UITextView {
),
size: size
)

let exclusionPath = UIBezierPath(rect: exclusionRect)
add(exclusionPath: exclusionPath)

self.leftExclusionPath = exclusionPath
}
}

Expand Down

0 comments on commit 7eb6fa3

Please # to comment.