Skip to content

Commit

Permalink
Merge pull request #110 from square/entin/scale-from-traits
Browse files Browse the repository at this point in the history
Get scale factor for view from trait collection instead of screen
  • Loading branch information
NickEntin authored Apr 17, 2024
2 parents 3fce4c7 + 1f443b9 commit a1f0be7
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 a1f0be7

Please sign in to comment.