Skip to content

Commit

Permalink
feat: GWRoundedShadwView 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
MaraMincho committed Nov 16, 2023
1 parent 211b940 commit c9eec97
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
10 changes: 5 additions & 5 deletions iOS/Projects/Shared/DesignSystem/Sources/GWPageConrol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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로 만드는게 맞을까?
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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),
Expand Down
66 changes: 66 additions & 0 deletions iOS/Projects/Shared/DesignSystem/Sources/GWRoundShadowView.swift
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit c9eec97

Please sign in to comment.