From 7fab1dbbc08c39404bef946979f6c3b28593730b Mon Sep 17 00:00:00 2001 From: qmchenry Date: Thu, 18 Jun 2020 11:57:34 -0400 Subject: [PATCH] Fix rounding errors that caused false positives --- Sources/UILint/UIKitHelpers.swift | 8 +++++++- Sources/UILint/UILabelChecks.swift | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/UILint/UIKitHelpers.swift b/Sources/UILint/UIKitHelpers.swift index f49cf86..1aeb305 100644 --- a/Sources/UILint/UIKitHelpers.swift +++ b/Sources/UILint/UIKitHelpers.swift @@ -26,7 +26,7 @@ extension UIView { // View's frame in global/window coordinates var windowFrame: CGRect? { - superview?.convert(frame, to: parentViewController()?.view) + superview?.convert(frame, to: parentViewController()?.view).rounded } // Return an array of all subviews including those not included in the @@ -46,6 +46,12 @@ extension UIView { } } +extension CGRect { + var rounded: CGRect { + CGRect(x: origin.x.rounded(), y: origin.y.rounded(), width: width.rounded(), height: height.rounded()) + } +} + extension UIImage { func crop(to rect: CGRect, viewSize: CGSize) -> UIImage { let cropScale = max(size.width/viewSize.width, size.height/viewSize.height) * scale diff --git a/Sources/UILint/UILabelChecks.swift b/Sources/UILint/UILabelChecks.swift index 6a5ceac..6a50574 100644 --- a/Sources/UILint/UILabelChecks.swift +++ b/Sources/UILint/UILabelChecks.swift @@ -27,7 +27,7 @@ extension Element { let frame = base.windowFrame else { return false } guard text.count > 0 else { return false } guard frame.width > 0 else { return true } - return labelSize().height > frame.size.height + return labelSize().height.rounded() > frame.size.height.rounded() } func isLabelOffscreen(windowSize: CGSize) -> Bool {