Skip to content

Instantly share code, notes, and snippets.

@farhan-syed
Created June 12, 2018 04:24
Show Gist options
  • Save farhan-syed/cb6f3171e1ecc658b4c7f1505f841c0c to your computer and use it in GitHub Desktop.
Save farhan-syed/cb6f3171e1ecc658b4c7f1505f841c0c to your computer and use it in GitHub Desktop.
extension UIImage {
func calcImageRatio() -> CGFloat {
let imageRatio = CGFloat(self.size.width / self.size.height)
return imageRatio
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let currentImage = images[indexPath.row]
let imageRatio = currentImage.calcImageRatio()
return tableView.frame.width / imageRatio
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment