Skip to content

Commit

Permalink
Fix ErrorView dynamic type resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
caiozullo committed Jan 9, 2024
1 parent 48be1be commit 3628bea
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions EssentialFeed/EssentialFeediOS/Shared UI/Views/ErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3628bea

Please sign in to comment.