Created
July 24, 2018 21:36
-
-
Save cscouto/23cb671179db7857ba32badfc235559b to your computer and use it in GitHub Desktop.
SWIFT - Add Shadows to UIView
This file contains 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
// | |
// 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