Created
September 14, 2017 10:31
-
-
Save sauravexodus/1c127677a3c289a03ac6d541e9800a67 to your computer and use it in GitHub Desktop.
Relative Dimensioning in Swift Manual Layouts
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
extension CGFloat { | |
/** | |
The relative dimension to the corresponding screen size. | |
//Usage | |
let someView = UIView(frame: CGRect(x: 0, y: 0, width: 320.dp, height: 40.dp) | |
**Warning** Only works with size references from @1x mockups. | |
*/ | |
var dp: CGFloat { | |
return (self / 320) * UIScreen.main.bounds.width | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment