From 7ea79b150a6fb446b1edb994e876a23e47567177 Mon Sep 17 00:00:00 2001 From: sycheon88 Date: Tue, 13 May 2025 18:35:10 +0900 Subject: [PATCH] feat(FSPagerViewCell): Add customizable shadow properties - Add shadow customization properties (color, radius, opacity, offset) - Implement updateShadow() method to apply shadow settings - Refactor commonInit() to use the new shadow update method - Keep backward compatibility with default values --- Sources/FSPagerViewCell.swift | 38 +++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/Sources/FSPagerViewCell.swift b/Sources/FSPagerViewCell.swift index 286eb38..db0e223 100644 --- a/Sources/FSPagerViewCell.swift +++ b/Sources/FSPagerViewCell.swift @@ -87,7 +87,28 @@ open class FSPagerViewCell: UICollectionViewCell { return super.isSelected } } - + + /// properties to control shadow appearance + @objc + open var shadowColor: UIColor = .black { + didSet { updateShadow() } + } + + @objc + open var shadowRadius: CGFloat = 5 { + didSet { updateShadow() } + } + + @objc + open var shadowOpacity: Float = 0.75 { + didSet { updateShadow() } + } + + @objc + open var shadowOffset: CGSize = .zero { + didSet { updateShadow() } + } + public override init(frame: CGRect) { super.init(frame: frame) commonInit() @@ -101,12 +122,17 @@ open class FSPagerViewCell: UICollectionViewCell { fileprivate func commonInit() { self.contentView.backgroundColor = UIColor.clear self.backgroundColor = UIColor.clear - self.contentView.layer.shadowColor = UIColor.black.cgColor - self.contentView.layer.shadowRadius = 5 - self.contentView.layer.shadowOpacity = 0.75 - self.contentView.layer.shadowOffset = .zero + // Apply the shadow settings + updateShadow() } - + + private func updateShadow() { + self.contentView.layer.shadowColor = shadowColor.cgColor + self.contentView.layer.shadowRadius = shadowRadius + self.contentView.layer.shadowOpacity = shadowOpacity + self.contentView.layer.shadowOffset = shadowOffset + } + deinit { if let textLabel = _textLabel { textLabel.removeObserver(self, forKeyPath: "font", context: kvoContext)