SwiftUIで画像を画像を丸く切り取る
SwiftUIで画像を画像を丸く切り取る方法です。 150✖︎150サイズに画像をリサイズし、丸く切り取って表示させています。 アスペクト比が異なる場合ははみ出た箇所を切り取って表示しています。

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
Image(.icon) | |
.resizable() | |
.aspectRatio(contentMode: .fill) | |
.frame(width: 150, height: 150) | |
.clipShape(Circle()) | |
} | |
} | |
#Preview { | |
ContentView() | |
} |