Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension CGSize {
- static func widthRatio(ratio: CGSize, width: Float) -> CGSize {
- let oldWidth = Float(ratio.width)
- let scaleFactor = width / oldWidth
- let newHeight = Float(ratio.height) * scaleFactor
- let newWidth = oldWidth * scaleFactor;
- return CGSize(width: CGFloat(newWidth), height: CGFloat(newHeight))
- }
- static func heightRatio(ratio: CGSize, height: Float) -> CGSize {
- let oldHeight = Float(ratio.width)
- let scaleFactor = height / oldHeight
- let newWidth = Float(ratio.width) * scaleFactor
- let newHeight = oldHeight * scaleFactor;
- return CGSize(width: CGFloat(newWidth), height: CGFloat(newHeight))
- }
- // EXAMPLE: CGSize.heightRatio(ratio: CGSize(width: 100, height: 100), height: 100)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement