Skip to content

Instantly share code, notes, and snippets.

@marcc-orange
marcc-orange / ScaledHeightImageView.swift
Last active April 5, 2023 09:22
An image view that can computes its intrinsic height from its width while preserving aspect ratio
import UIKit
/// An image view that computes its intrinsic height from its width while preserving aspect ratio
/// Source: https://stackoverflow.com/a/48476446
class ScaledHeightImageView: UIImageView {
// Track the width that the intrinsic size was computed for,
// to invalidate the intrinsic size when needed
private var layoutedWidth: CGFloat = 0