diff --git a/Source/PopTip.swift b/Source/PopTip.swift index 2e89dcfc..200c7a42 100644 --- a/Source/PopTip.swift +++ b/Source/PopTip.swift @@ -691,7 +691,13 @@ open class PopTip: UIView { containerView = view let controller = UIHostingController(rootView: rootView) controller.view.backgroundColor = .clear - let maxContentWidth = UIScreen.main.bounds.width - (self.edgeMargin * 2) - self.edgeInsets.horizontal - (self.padding * 2) + let maxContentWidth: CGFloat + if let window = parent.view.window { + maxContentWidth = window.bounds.width - (self.edgeMargin * 2) - self.edgeInsets.horizontal - (self.padding * 2) + } + else { + maxContentWidth = .greatestFiniteMagnitude + } let sizeThatFits = controller.view.sizeThatFits(CGSize(width: maxContentWidth, height: CGFloat.greatestFiniteMagnitude)) controller.view.frame.size = CGSize(width: min(sizeThatFits.width, maxContentWidth), height: sizeThatFits.height) maxWidth = controller.view.frame.size.width