Skip to content

Instantly share code, notes, and snippets.

View kris-randen's full-sized avatar
💭
𝗖𝗵𝗮𝘁 🙊 𝙶𝙿𝚃 🤖 | 𝗌𝖼𝗋𝗮𝗽𝗽𝗒 🛠️🤖

Kris Rajendren kris-randen

💭
𝗖𝗵𝗮𝘁 🙊 𝙶𝙿𝚃 🤖 | 𝗌𝖼𝗋𝗮𝗽𝗽𝗒 🛠️🤖
View GitHub Profile
@karigrooms
karigrooms / swiftui-resize-image-and-maintain-aspect-ratio.swift
Last active April 6, 2023 11:54
ViewModifier for resizing images in SwiftUI. Resize an image to any size (square, circle, rectangle) while maintaining its aspect ratio.
import SwiftUI
/// Common aspect ratios
public enum AspectRatio: CGFloat {
case square = 1
case threeToFour = 0.75
case fourToThree = 1.75
}
/// Fit an image to a certain aspect ratio while maintaining its aspect ratio