Skip to content

Commit

Permalink
Get scale factor for view from trait collection instead of screen
Browse files Browse the repository at this point in the history
  • Loading branch information
NickEntin committed Apr 16, 2024
1 parent ce04c4d commit 1f443b9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Paralayout/PixelRounding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ extension UIScreen: ScaleFactorProviding {
extension UIView: ScaleFactorProviding {

public var pixelsPerPoint: CGFloat {
let scaleFromTraits = traitCollection.displayScale

// The trait collection is the authority for display scale, but sometimes the trait collection does not have a
// value for the scale, in which case it will return 0, breaking all the things.
if scaleFromTraits > 0 {
return scaleFromTraits
}

#if os(iOS)
return (window?.screen ?? UIScreen.main).pixelsPerPoint
#endif
}

}
Expand Down

0 comments on commit 1f443b9

Please sign in to comment.