티스토리 뷰
제플린 등에서 제공하는 그림자 요소들을 쉽게 swiftf로 만들어주는 extension입니다.
extension CALayer {
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
}
}
}
예시
Swift
layer.applySketchShadow(color: .black, alpha: 0.3, x: 0, y: 0, blur: 13, spread: 0)
'iOS' 카테고리의 다른 글
[iOS] iOS15 UIButton, setTitle with RxSwift (0) | 2022.02.11 |
---|---|
[iOS] Custom UIView에 UIButton Touch 안될 때 (0) | 2022.01.15 |
[iOS] What are Frameworks? 번역 / 프레임워크란? (0) | 2021.12.14 |
[iOS] PinLayout 문서 번역(1) (0) | 2021.11.29 |
[iOS] Contacts 연락처 사용하기 (0) | 2021.11.25 |
댓글
공지사항