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 November 28, 2024 19:53
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