Skip to content

Instantly share code, notes, and snippets.

@cscouto
Created July 24, 2018 21:36
Show Gist options
  • Save cscouto/23cb671179db7857ba32badfc235559b to your computer and use it in GitHub Desktop.
Save cscouto/23cb671179db7857ba32badfc235559b to your computer and use it in GitHub Desktop.
SWIFT - Add Shadows to UIView
//
// UIView+Shadows.swift
// brasileirao
//
// Created by Tiago Do Couto on 7/24/18.
// Copyright © 2018 coutocode. All rights reserved.
//
import UIKit
extension UIView {
func dropShadow(scale: Bool = true) {
layer.masksToBounds = false
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 0.5
layer.shadowOffset = CGSize(width: -1, height: 1)
layer.shadowRadius = 1
layer.shadowPath = UIBezierPath(rect: bounds).cgPath
layer.shouldRasterize = true
layer.rasterizationScale = scale ? UIScreen.main.scale : 1
}
func dropShadow(color: UIColor, opacity: Float = 0.5, offSet: CGSize, radius: CGFloat = 1, scale: Bool = true) {
layer.masksToBounds = false
layer.shadowColor = color.cgColor
layer.shadowOpacity = opacity
layer.shadowOffset = offSet
layer.shadowRadius = radius
layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath
layer.shouldRasterize = true
layer.rasterizationScale = scale ? UIScreen.main.scale : 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment