Skip to content

Commit

Permalink
Fix rounding errors that caused false positives
Browse files Browse the repository at this point in the history
  • Loading branch information
qmchenry committed Jun 18, 2020
1 parent e0f7d7e commit 7fab1db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Sources/UILint/UIKitHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/UILint/UILabelChecks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7fab1db

Please sign in to comment.