Last active
May 2, 2022 07:16
-
-
Save sourleangchhean168/f41a70e4d284c39da931f92c8f6c6213 to your computer and use it in GitHub Desktop.
Aspect Ratio in Swift
This file contains 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
//iOS 13, swift 5.1 | |
//Example programmatic constraints with aspect ratio. | |
imageView.translatesAutoresizingMaskIntoConstraints = false | |
//A) 4:3 | |
imageView.heightAnchor.constraint(equalTo: widthAnchor, multiplier: 3.0/4.0).isActive = true | |
//B) 16:9 | |
imageView.heightAnchor.constraint(equalTo: widthAnchor, multiplier: 9.0/16.0).isActive = true | |
//Ref: https://stackoverflow.com/questions/52805754/image-view-169-aspect-ratio |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment