Created
February 10, 2023 12:57
-
-
Save karambirov/fc83e4a18ebfbf0e40b300d410a5d80f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public extension UIView { | |
func compactSystemLayoutFittingSizeFor(width: CGFloat) -> CGSize { | |
let targetSize = CGSize( | |
width: width, | |
height: UIView.layoutFittingCompressedSize.height | |
) | |
return systemLayoutSizeFitting( | |
targetSize, | |
withHorizontalFittingPriority: .required, | |
verticalFittingPriority: .fittingSizeLevel | |
) | |
} | |
func compactSystemLayoutFittingSizeFor(height: CGFloat) -> CGSize { | |
let targetSize = CGSize( | |
width: UIView.layoutFittingCompressedSize.width, | |
height: height | |
) | |
return systemLayoutSizeFitting( | |
targetSize, | |
withHorizontalFittingPriority: .fittingSizeLevel, | |
verticalFittingPriority: .required | |
) | |
} | |
func expandedSystemLayoutFittingSizeFor(width: CGFloat) -> CGSize { | |
let targetSize = CGSize( | |
width: width, | |
height: UIView.layoutFittingExpandedSize.height | |
) | |
return systemLayoutSizeFitting( | |
targetSize, | |
withHorizontalFittingPriority: .required, | |
verticalFittingPriority: .fittingSizeLevel | |
) | |
} | |
func compactSystemLayoutFittingHeightFor(width: CGFloat) -> CGFloat { | |
return compactSystemLayoutFittingSizeFor(width: width).height | |
} | |
func compactSystemLayoutFittingWidthFor(height: CGFloat) -> CGFloat { | |
return compactSystemLayoutFittingSizeFor(height: height).width | |
} | |
func expandedSystemLayoutFittingHeightFor(width: CGFloat) -> CGFloat { | |
expandedSystemLayoutFittingSizeFor(width: width).height | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment