diff --git a/iOS/Projects/Shared/DesignSystem/Sources/GWPageConrol.swift b/iOS/Projects/Shared/DesignSystem/Sources/GWPageConrol.swift index 96c05c27..5c82baf7 100644 --- a/iOS/Projects/Shared/DesignSystem/Sources/GWPageConrol.swift +++ b/iOS/Projects/Shared/DesignSystem/Sources/GWPageConrol.swift @@ -10,13 +10,13 @@ import Foundation import UIKit -// MARK: - TNPageControl +// MARK: - GWPageControl public final class GWPageControl: UIView { let countOfPage: Int var currentPageIndex: Int = 0 let spacing: CGFloat = 8 - var pages: [RoundShadowView] = [] + var pages: [GWRoundShadowView] = [] var pageswidthConstraint: [NSLayoutConstraint] = [] // MARK: - 과연 UIVIew를 optional로 만드는게 맞을까? @@ -55,7 +55,7 @@ public final class GWPageControl: UIView { private extension GWPageControl { func makePages() { - pages = (0 ..< countOfPage).enumerated().map { _, _ -> RoundShadowView in + pages = (0 ..< countOfPage).enumerated().map { _, _ -> GWRoundShadowView in return pageViewObject } } @@ -82,8 +82,8 @@ private extension GWPageControl { } } - var pageViewObject: RoundShadowView { - let view = RoundShadowView( + var pageViewObject: GWRoundShadowView { + let view = GWRoundShadowView( shadow: .init( shadowColor: DesignSystemColor.gray02.cgColor, shadowOffset: CGSize(width: 0, height: 1), diff --git a/iOS/Projects/Shared/DesignSystem/Sources/GWRoundShadowView.swift b/iOS/Projects/Shared/DesignSystem/Sources/GWRoundShadowView.swift new file mode 100644 index 00000000..7d1cda3b --- /dev/null +++ b/iOS/Projects/Shared/DesignSystem/Sources/GWRoundShadowView.swift @@ -0,0 +1,66 @@ +// +// GWRoundShadowView.swift +// DesignSystem +// +// Created by MaraMincho on 11/16/23. +// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved. +// + +import UIKit + +// MARK: - GWRoundShadowView + +public final class GWRoundShadowView: UIView { + let containerView = UIView() + let cornerRadius: CGFloat + let customShadow: CustomShadow + private var shadowLayer: CAShapeLayer! + private var fillColor: CGColor = UIColor.blue.cgColor + + public func update(color: UIColor) { + fillColor = color.cgColor + } + + override public func layoutSubviews() { + super.layoutSubviews() + if shadowLayer == nil { + shadowLayer = CAShapeLayer() + + shadowLayer.path = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath + shadowLayer.fillColor = fillColor + + shadowLayer.shadowColor = customShadow.shadowColor + shadowLayer.shadowPath = shadowLayer.path + shadowLayer.shadowOffset = customShadow.shadowOffset + shadowLayer.shadowOpacity = customShadow.shadowOpacity + shadowLayer.shadowRadius = customShadow.shadowRadius + + layer.insertSublayer(shadowLayer, at: 0) + } + + if shadowLayer.fillColor != fillColor { + shadowLayer.fillColor = fillColor + } + } + + init(shadow: CustomShadow, cornerRadius: CGFloat, backgroundColor: CGColor) { + customShadow = shadow + self.cornerRadius = cornerRadius + fillColor = backgroundColor + super.init(frame: .zero) + } + + @available(*, unavailable) + required init?(coder _: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +// MARK: - CustomShadow + +struct CustomShadow { + let shadowColor: CGColor + let shadowOffset: CGSize + let shadowOpacity: Float + let shadowRadius: CGFloat +}