From d2a948c5b56808237f8ed80b9d24e2842a926d79 Mon Sep 17 00:00:00 2001 From: Hyemin Heo Date: Thu, 16 May 2024 22:10:03 +0900 Subject: [PATCH] =?UTF-8?q?#26=20[Style]=20imagePlaceHolder=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Score/Score/Extension/Image+.swift | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Score/Score/Extension/Image+.swift diff --git a/Score/Score/Extension/Image+.swift b/Score/Score/Extension/Image+.swift new file mode 100644 index 0000000..60bf945 --- /dev/null +++ b/Score/Score/Extension/Image+.swift @@ -0,0 +1,59 @@ +// +// Image+.swift +// Score +// +// Created by sole on 4/27/24. +// + +import SwiftUI + +//MARK: - Image+imagePlaceHolder + +extension Image { + + //MARK: - imagePlaceHolder + + /// image 플레이스 홀더가 필요한 사진의 경우에 사용합니다. + /// 플레이스 홀더를 원형의 size*size로 생성합니다. + @ViewBuilder + func imagePlaceHolder(size: CGFloat) -> some View { + self + .resizable() + .frame(width: 130, + height: 130) + .clipShape(Circle()) + .background { + Circle() + .frame(width: size, + height: size) + .foregroundStyle( + Color.brandColor(color: .gray2) + ) + } + .frame(width: size, + height: size) + } +} + +extension Image? { + + @ViewBuilder + func imagePlaceHolder(size: CGFloat) -> some View { + let image: Image = self ?? Image("") + image + .resizable() + .frame(width: 130, + height: 130) + .clipShape(Circle()) + .background { + Circle() + .frame(width: size, + height: size) + .foregroundStyle( + Color.brandColor(color: .gray2) + ) + } + .frame(width: size, + height: size) + } +}