-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
211b940
commit c9eec97
Showing
2 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
iOS/Projects/Shared/DesignSystem/Sources/GWRoundShadowView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |