// // UIImage+Icon.swift // VDS // // Created by Matt Bruce on 3/11/24. // import Foundation import UIKit extension UIImage { /// UIImage helper for finding images based on the Icon.Name which uses the internal BundleManager. /// - Parameters: /// - name: RawRepresentable. /// - color: Color to Tint the image with /// - renderingMode: UIImage Rendering mode. /// - Returns: UIImage for this proecess public static func image(representing representable: T, color: UIColor? = nil, renderingMode: UIImage.RenderingMode = .alwaysOriginal) -> UIImage? where T.RawValue == String { guard let image = BundleManager.shared.image(for: representable.rawValue) else { return nil } guard let color else { return image } return image.withTintColor(color, renderingMode: renderingMode) } /// Resizes image to a specific Size /// - Parameter size: Size to resize /// - Returns: Image that is resized public func resized(to size: CGSize) -> UIImage? { UIGraphicsBeginImageContextWithOptions(size, false, 0.0) defer { UIGraphicsEndImageContext() } draw(in: .init(origin: .zero, size: size)) return UIGraphicsGetImageFromCurrentImageContext() } }