From 5f040ed390e7fd5cf05b403b2537da7d54831423 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 20 Jul 2024 11:08:59 -0700 Subject: [PATCH] Workaround text view not being baseline-aligned with label Closes #509 --- .../ProfileFieldValueView.swift | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Tusker/Views/Profile Header/ProfileFieldValueView.swift b/Tusker/Views/Profile Header/ProfileFieldValueView.swift index b1e64b55..e15a6285 100644 --- a/Tusker/Views/Profile Header/ProfileFieldValueView.swift +++ b/Tusker/Views/Profile Header/ProfileFieldValueView.swift @@ -54,8 +54,8 @@ class ProfileFieldValueView: UIView { textView.isScrollEnabled = false textView.isSelectable = false textView.isEditable = false - textView.textContainerInset = .zero textView.font = .preferredFont(forTextStyle: .body) + updateTextContainerInset() textView.adjustsFontForContentSizeCategory = true textView.attributedText = converted textView.setEmojis(account.emojis, identifier: account.id) @@ -108,6 +108,27 @@ class ProfileFieldValueView: UIView { return size } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + if traitCollection.preferredContentSizeCategory != previousTraitCollection?.preferredContentSizeCategory { + updateTextContainerInset() + } + } + + private func updateTextContainerInset() { + // blergh + switch traitCollection.preferredContentSizeCategory { + case .extraSmall: + textView.textContainerInset = UIEdgeInsets(top: 4, left: 0, bottom: 0, right: 0) + case .small: + textView.textContainerInset = UIEdgeInsets(top: 3, left: 0, bottom: 0, right: 0) + case .medium, .large: + textView.textContainerInset = UIEdgeInsets(top: 2, left: 0, bottom: 0, right: 0) + default: + textView.textContainerInset = .zero + } + } + func setTextAlignment(_ alignment: NSTextAlignment) { textView.textAlignment = alignment }