From 045524f6a5701b8c5ce8a396b780eb31c119cf65 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Wed, 10 Mar 2021 17:40:03 -0800 Subject: [PATCH] Caption max height --- View Controllers/ImageViewController.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/View Controllers/ImageViewController.swift b/View Controllers/ImageViewController.swift index e6bb18d..ad4ac2c 100644 --- a/View Controllers/ImageViewController.swift +++ b/View Controllers/ImageViewController.swift @@ -111,6 +111,7 @@ final class ImageViewController: UIViewController { descriptionBackgroundView.leadingAnchor.constraint(equalTo: view.leadingAnchor), descriptionBackgroundView.trailingAnchor.constraint(equalTo: view.trailingAnchor), descriptionBackgroundView.bottomAnchor.constraint(equalTo: view.bottomAnchor), + descriptionTextView.heightAnchor.constraint(lessThanOrEqualTo: view.heightAnchor, multiplier: 1 / 4), descriptionTextView.leadingAnchor.constraint( equalTo: descriptionBackgroundView.layoutMarginsGuide.leadingAnchor), descriptionTextView.topAnchor.constraint(equalTo: descriptionBackgroundView.topAnchor), @@ -172,6 +173,15 @@ final class ImageViewController: UIViewController { ?? Attachment.AttachmentType.image.accessibilityName contentView.isAccessibilityElement = true } + + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + + let textHeight = descriptionTextView.sizeThatFits(.init( + width: descriptionTextView.frame.width, + height: .greatestFiniteMagnitude)).height + descriptionTextView.isScrollEnabled = textHeight > descriptionTextView.frame.height + } } extension ImageViewController {