Skip to content

Instantly share code, notes, and snippets.

@BrunoScheltzke
Last active July 29, 2020 13:11
Show Gist options
  • Save BrunoScheltzke/fa00df5bcdb75825e49dd6d95111907f to your computer and use it in GitHub Desktop.
Save BrunoScheltzke/fa00df5bcdb75825e49dd6d95111907f to your computer and use it in GitHub Desktop.
//
// 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