Last active
July 29, 2020 13:11
-
-
Save BrunoScheltzke/fa00df5bcdb75825e49dd6d95111907f 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
// | |
// ShadowView.swift | |
// | |
// Created by Bruno Scheltzke on 14/06/20. | |
// Copyright © Bruno Scheltzke. All rights reserved. | |
// | |
import UIKit | |
@IBDesignable | |
class ShadowView: UIView { | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
setupShadow() | |
} | |
override var bounds: CGRect { | |
didSet { | |
setupShadow() | |
} | |
} | |
@IBInspectable | |
var radius: CGFloat = 2 | |
func setupShadow(offset: CGSize = CGSize(width: 0, height: 4)) { | |
self.layer.cornerRadius = radius | |
self.layer.shadowOffset = offset | |
self.layer.shadowRadius = 4 | |
self.layer.shadowOpacity = 0.1 | |
self.layer.shadowPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: radius, height: radius)).cgPath | |
self.layer.shouldRasterize = true | |
self.layer.rasterizationScale = UIScreen.main.scale | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment