以下の内容はhttps://xyk.hatenablog.com/entry/2020/08/22/220529より取得しました。


UIImageView の画像に AspectFit を適用した後の画像サイズを知る方法

検証環境:
Xcode 11.4
Swift 5.2

UIImageView の画像に AspectFit を適用した後の画像サイズは、AVFoundation の AVMakeRect(aspectRatio:insideRect:) を使うと自分で計算せずに簡単にサイズを知ることができます。

UIImageView の Extension として実装してみました。

import AVFoundation

extension UIImageView {
    
    var imageSize: CGSize {
        if let image = image {
            return AVMakeRect(aspectRatio: image.size, insideRect: bounds).size
        }
        return .zero
    }
}

https://developer.apple.com/documentation/avfoundation/1390116-avmakerect




以上の内容はhttps://xyk.hatenablog.com/entry/2020/08/22/220529より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14