From 3628bea1bed6e0bc51d0cd8149b78cba69d36b94 Mon Sep 17 00:00:00 2001 From: Caio Zullo Date: Tue, 9 Jan 2024 09:34:56 +0100 Subject: [PATCH] Fix ErrorView dynamic type resizing --- .../Shared UI/Views/ErrorView.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/EssentialFeed/EssentialFeediOS/Shared UI/Views/ErrorView.swift b/EssentialFeed/EssentialFeediOS/Shared UI/Views/ErrorView.swift index 3e650342..f9438a5c 100644 --- a/EssentialFeed/EssentialFeediOS/Shared UI/Views/ErrorView.swift +++ b/EssentialFeed/EssentialFeediOS/Shared UI/Views/ErrorView.swift @@ -21,6 +21,25 @@ public final class ErrorView: UIButton { super.init(coder: coder) } + public override var intrinsicContentSize: CGSize { + guard + let size = titleLabel?.intrinsicContentSize, + let insets = configuration?.contentInsets + else { + return super.intrinsicContentSize + } + + return CGSize(width: size.width + insets.leading + insets.trailing, height: size.height + insets.top + insets.bottom) + } + + public override func layoutSubviews() { + super.layoutSubviews() + + if let insets = configuration?.contentInsets { + titleLabel?.preferredMaxLayoutWidth = bounds.size.width - insets.leading - insets.trailing + } + } + private var titleAttributes: AttributeContainer { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = NSTextAlignment.center