Merge pull request #814 from j-f1/alt-scroll
Allow AltViewController text to scroll + increase HUDButton contrast
This commit is contained in:
commit
80c145111a
|
@ -9,7 +9,14 @@ import SwiftUI
|
|||
|
||||
class AltViewController: UIViewController {
|
||||
private var alt: String
|
||||
let label = UITextView()
|
||||
let label = {
|
||||
if #available(iOS 16, *) {
|
||||
// TODO: update code below to use TextKit 2 when dropping iOS 15 support
|
||||
return UITextView(usingTextLayoutManager: false)
|
||||
} else {
|
||||
return UITextView()
|
||||
}
|
||||
}()
|
||||
|
||||
init(alt: String, sourceView: UIView?) {
|
||||
self.alt = alt
|
||||
|
@ -24,6 +31,11 @@ class AltViewController: UIViewController {
|
|||
@MainActor required dynamic init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func loadView() {
|
||||
super.loadView()
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
@ -38,22 +50,20 @@ class AltViewController: UIViewController {
|
|||
right: 0
|
||||
)
|
||||
label.font = .preferredFont(forTextStyle: .callout)
|
||||
label.isScrollEnabled = false
|
||||
label.isScrollEnabled = true
|
||||
label.backgroundColor = .clear
|
||||
label.isOpaque = false
|
||||
label.isEditable = false
|
||||
label.tintColor = .white
|
||||
label.text = alt
|
||||
label.textContainerInset = UIEdgeInsets(top: 12, left: 8, bottom: 8, right: 8)
|
||||
label.contentInsetAdjustmentBehavior = .always
|
||||
label.verticalScrollIndicatorInsets.bottom = 4
|
||||
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.backgroundColor = .systemBackground
|
||||
view.addSubview(label)
|
||||
|
||||
NSLayoutConstraint.activate(
|
||||
NSLayoutConstraint.constraints(withVisualFormat: "V:|-[label]-|", metrics: nil, views: ["label": label])
|
||||
)
|
||||
NSLayoutConstraint.activate(
|
||||
NSLayoutConstraint.constraints(withVisualFormat: "H:|-(8)-[label]-(8)-|", metrics: nil, views: ["label": label])
|
||||
)
|
||||
label.pinToParent()
|
||||
NSLayoutConstraint.activate([
|
||||
label.widthAnchor.constraint(lessThanOrEqualToConstant: 400),
|
||||
])
|
||||
|
@ -62,12 +72,18 @@ class AltViewController: UIViewController {
|
|||
override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
UIView.performWithoutAnimation {
|
||||
let size = label.layoutManager.boundingRect(forGlyphRange: NSMakeRange(0, (label.textStorage.string as NSString).length), in: label.textContainer).size
|
||||
preferredContentSize = CGSize(
|
||||
width: label.intrinsicContentSize.width + 16,
|
||||
height: label.intrinsicContentSize.height + view.layoutMargins.top + view.layoutMargins.bottom
|
||||
width: size.width + (8 + label.textContainer.lineFragmentPadding) * 2,
|
||||
height: size.height + 12 + (label.textContainer.lineFragmentPadding * 2)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||
super.traitCollectionDidChange(previousTraitCollection)
|
||||
label.font = .preferredFont(forTextStyle: .callout)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: UIPopoverPresentationControllerDelegate
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
import UIKit
|
||||
|
||||
extension UIEdgeInsets {
|
||||
public init(horizontal: CGFloat, vertical: CGFloat) {
|
||||
self.init(top: vertical, left: horizontal, bottom: vertical, right: horizontal)
|
||||
}
|
||||
public static func constant(_ offset: CGFloat) -> Self {
|
||||
UIEdgeInsets(top: offset, left: offset, bottom: offset, right: offset)
|
||||
}
|
||||
|
|
|
@ -12,18 +12,17 @@ public class HUDButton: UIView {
|
|||
public static let height: CGFloat = 30
|
||||
|
||||
let background: UIVisualEffectView = {
|
||||
let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemUltraThinMaterial))
|
||||
backgroundView.alpha = 0.9
|
||||
let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
|
||||
backgroundView.layer.masksToBounds = true
|
||||
backgroundView.layer.cornerRadius = HUDButton.height * 0.5
|
||||
return backgroundView
|
||||
}()
|
||||
|
||||
let vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: .systemUltraThinMaterial)))
|
||||
let vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: .systemMaterial)))
|
||||
|
||||
public let button: UIButton = {
|
||||
let button = HighlightDimmableButton()
|
||||
button.expandEdgeInsets = UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10)
|
||||
button.expandEdgeInsets = .constant(-10)
|
||||
button.contentEdgeInsets = .constant(7)
|
||||
button.imageView?.tintColor = .label
|
||||
button.titleLabel?.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .bold))
|
||||
|
|
Loading…
Reference in New Issue