diff --git a/Sources/SDSKit/Color/SDS-UIColor+.swift b/Sources/SDSKit/Color/SDS-UIColor+.swift index 28d842b..8efd289 100644 --- a/Sources/SDSKit/Color/SDS-UIColor+.swift +++ b/Sources/SDSKit/Color/SDS-UIColor+.swift @@ -5,6 +5,15 @@ import UIKit public extension UIColor { + /// hex code를 이용하여 정의 + convenience init(hex: UInt, alpha: CGFloat = 1.0) { + self.init( + red: CGFloat((hex & 0xFF0000) >> 16) / 255.0, + green: CGFloat((hex & 0x00FF00) >> 8) / 255.0, + blue: CGFloat(hex & 0x0000FF) / 255.0, + alpha: CGFloat(alpha) + ) + } // gray static let gray000 = UIColor(named: "Gray000", in: .module, compatibleWith: nil)! static let gray50 = UIColor(named: "Gray50", in: .module, compatibleWith: nil)! diff --git a/Sources/SDSKit/Elevations/SDSElevations.swift b/Sources/SDSKit/Elevations/SDSElevations.swift new file mode 100644 index 0000000..a7917dc --- /dev/null +++ b/Sources/SDSKit/Elevations/SDSElevations.swift @@ -0,0 +1,123 @@ + +#if canImport(UIKit) +import UIKit +import SnapKit +#endif + +extension UIView { + public func applyBlurAndDepth2_2Shadow() { + let blurEffect = UIBlurEffect(style: .light) + let blurEffectView = UIVisualEffectView(effect: blurEffect) + blurEffectView.alpha = 1 + blurEffectView.frame = bounds + blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + blurEffectView.layer.cornerRadius = 20 + blurEffectView.clipsToBounds = true + addSubview(blurEffectView) + } + + public func applyDepth3_2Shadow() { + let blurEffect = UIBlurEffect(style: .light) + let blurEffectView = UIVisualEffectView(effect: blurEffect) + blurEffectView.alpha = 1 + blurEffectView.frame = bounds + blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + blurEffectView.layer.cornerRadius = 20 + blurEffectView.clipsToBounds = true + addSubview(blurEffectView) + } + public func applyNavigationBarShadow() { + let blurEffect = UIBlurEffect(style: .light) + let blurEffectView = UIVisualEffectView(effect: blurEffect) + blurEffectView.alpha = 1 + blurEffectView.frame = bounds + blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + addSubview(blurEffectView) + } +} + +extension CALayer { + public func applyDepth1Shadow() { + masksToBounds = false + shadowColor = UIColor(hex: 0x0F2726).cgColor + shadowOpacity = 0.1 + shadowOffset = CGSize(width: -1, height: 1) + shadowRadius = 6 / UIScreen.main.scale + shadowPath = nil + } + + public func applyDepth2_2Shadow() { + masksToBounds = false + shadowColor = UIColor(hex: 0xE9EFEF).cgColor + shadowOpacity = 1 + shadowOffset = CGSize(width: -3, height: -3) + shadowRadius = 10 / UIScreen.main.scale + shadowPath = nil + } + public func applyDepth2_1Shadow() { + masksToBounds = false + shadowColor = UIColor(hex: 0xABBABA).cgColor + shadowOpacity = 0.12 + shadowOffset = CGSize(width: 6, height: 7) + shadowRadius = 25 / UIScreen.main.scale + let rect = bounds.insetBy(dx: -11, dy: -11) + shadowPath = UIBezierPath(rect: rect).cgPath + } + public func applyBlurAndDepth2_1Shadow() { + masksToBounds = false + shadowColor = UIColor(hex: 0x4E4E4E).cgColor + shadowOpacity = 0.13 + shadowOffset = CGSize(width: 1, height: 4) + shadowRadius = 25 / UIScreen.main.scale + shadowPath = nil + } + + public func applyDepthAndDepth3_1Shadow() { + masksToBounds = false + shadowColor = UIColor(hex: 0x000000).cgColor + shadowOpacity = 0.25 + shadowOffset = CGSize(width: 0, height: 0) + shadowRadius = 10 / UIScreen.main.scale + shadowPath = nil + } + + public func applyDepth4_1Shadow() { + masksToBounds = false + shadowColor = UIColor(hex: 0x262626).cgColor + shadowOpacity = 0.10 + shadowOffset = CGSize(width: 2, height: 0) + shadowRadius = 3 / UIScreen.main.scale + shadowPath = nil + } + public func applyDepth4_2Shadow() { + masksToBounds = false + shadowColor = UIColor(hex: 0x262626).cgColor + shadowOpacity = 0.15 + shadowOffset = CGSize(width: 0, height: 4) + shadowRadius = 20 / UIScreen.main.scale + shadowPath = nil + } +} + +extension CALayer { + public func applySketchShadow( + color: UIColor, + alpha: Float, + x: CGFloat, + y: CGFloat, + blur: CGFloat, + spread: CGFloat + ) { + masksToBounds = false + shadowColor = color.cgColor + shadowOpacity = alpha + shadowOffset = CGSize(width: x, height: y) + shadowRadius = blur / UIScreen.main.scale + if spread == 0 { + shadowPath = nil + } else { + let rect = bounds.insetBy(dx: -spread, dy: -spread) + shadowPath = UIBezierPath(rect: rect).cgPath + } + } +}