diff --git a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift index fb9aef0c2..a86edb2b7 100644 --- a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift +++ b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift @@ -14,8 +14,10 @@ class MasterFeedUnreadCountView : UIView { private let cornerRadius = 8.0 private let bgColor = UIColor.darkGray private let textColor = UIColor.white - private let textFont = UIFont.preferredFont(forTextStyle: .caption1) - private lazy var textAttributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()] + private var textAttributes: [NSAttributedString.Key: AnyObject] { + let textFont = UIFont.preferredFont(forTextStyle: .caption1) + return [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()] + } private var textSizeCache = [Int: CGSize]() var unreadCount = 0 { @@ -42,6 +44,12 @@ class MasterFeedUnreadCountView : UIView { self.isOpaque = false } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + textSizeCache = [Int: CGSize]() + invalidateIntrinsicContentSize() + setNeedsDisplay() + } + override var intrinsicContentSize: CGSize { if !intrinsicContentSizeIsValid { var size = CGSize.zero