Skip to content

Commit

Permalink
Fix text view inset on AcknowViewController for layout margins/safe…
Browse files Browse the repository at this point in the history
… area

Remove support for “readable content guide” on `AcknowViewController`
  • Loading branch information
vtourraine committed Jun 15, 2018
1 parent ea8f796 commit cf5c82d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog


## 1.6.1 (work in progress)

- Fix text view inset on `AcknowViewController` (support layout margins, safe area insets)
- Remove support for “readable content guide” on `AcknowViewController`


## 1.6 (20 March 2018)

- Add tvOS support, by Tobias Tiemerding (@honkmaster)
Expand Down
34 changes: 20 additions & 14 deletions Source/AcknowViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ open class AcknowViewController: UIViewController {

// MARK: - View lifecycle

let TopBottomDefaultMargin: CGFloat = 20
let LeftRightDefaultMargin: CGFloat = 10

/// Called after the controller'€™s view is loaded into memory.
open override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -74,32 +77,35 @@ open class AcknowViewController: UIViewController {

view.backgroundColor = UIColor.white
#endif
textView.textContainerInset = UIEdgeInsetsMake(TopBottomDefaultMargin, LeftRightDefaultMargin, TopBottomDefaultMargin, LeftRightDefaultMargin)
view.addSubview(textView)

self.textView = textView

if #available(iOS 9.0, *) {
textView.translatesAutoresizingMaskIntoConstraints = false

let marginGuide = view.readableContentGuide
NSLayoutConstraint.activate([
textView.topAnchor.constraint(equalTo: marginGuide.topAnchor),
textView.bottomAnchor.constraint(equalTo: marginGuide.bottomAnchor),
textView.leadingAnchor.constraint(equalTo: marginGuide.leadingAnchor),
textView.trailingAnchor.constraint(equalTo: marginGuide.trailingAnchor)])
}
else {
textView.textContainerInset = UIEdgeInsetsMake(12, 10, 12, 10)
}
}

/// Called to notify the view controller that its view has just laid out its subviews.
open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

if let textView = textView {
updateTextViewInsets(textView)
}

// Need to set the textView text after the layout is completed, so that the content inset and offset properties can be adjusted automatically.
if let acknowledgement = self.acknowledgement {
textView?.text = acknowledgement.text
}
}

@available(iOS 11.0, *) open override func viewLayoutMarginsDidChange() {
super.viewLayoutMarginsDidChange()

if let textView = textView {
updateTextViewInsets(textView)
}
}

func updateTextViewInsets(_ textView: UITextView) {
textView.textContainerInset = UIEdgeInsetsMake(TopBottomDefaultMargin, self.view.layoutMargins.left, TopBottomDefaultMargin, self.view.layoutMargins.right);
}
}

0 comments on commit cf5c82d

Please sign in to comment.