Created
March 14, 2020 14:17
-
-
Save SwiftyAlex/bb0311e249e0657aaa7198cd8a397963 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import UIKit | |
@propertyWrapper class Card { | |
var wrappedValue: UIView | |
init(wrappedValue: UIView) { | |
self.wrappedValue = wrappedValue | |
applyCornerRadius() | |
applyCardShadow() | |
} | |
private func applyCardShadow() { | |
applySubtleShadow() | |
} | |
private func applySubtleShadow() { | |
let layer = wrappedValue.layer | |
layer.shadowColor = UIColor.black.cgColor | |
layer.shadowOffset = CGSize.zero | |
layer.shadowRadius = 8 | |
layer.shadowOpacity = 0.35 | |
} | |
private func applyCornerRadius(_ radius: CGFloat = 8, forCorners cornerMask: CACornerMask = .all) { | |
let layer = wrappedValue.layer | |
layer.cornerCurve = .continuous | |
layer.cornerRadius = radius | |
layer.maskedCorners = cornerMask | |
} | |
} | |
// Usage | |
@Card() | |
var header = UIView() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment