Files
GitHawk/Classes/Views/BoundedImageSize.swift
Ryan Nystrom b8bacd5f9c Web image height capped, center images (#1421)
* larger overlay min height

* cap html image heights, center image crops
2018-01-14 23:13:33 -05:00

24 lines
637 B
Swift

//
// BoundedImageSize.swift
// Freetime
//
// Created by Ryan Nystrom on 11/9/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import UIKit
func BoundedImageSize(originalSize: CGSize, containerWidth: CGFloat) -> CGSize {
guard originalSize.width > containerWidth else {
return CGSize(
width: containerWidth,
height: min(originalSize.height, Styles.Sizes.maxImageHeight)
)
}
let ratio = originalSize.width / originalSize.height
return CGSize(
width: containerWidth,
height: min(ceil(containerWidth / ratio), Styles.Sizes.maxImageHeight)
)
}