iOS Swift SSView
Change gradient background Rounded corners Shadow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
import UIKit @IBDesignable class SSView: UIView { @IBInspectable var GradientFirstColor :UIColor = UIColor.clear { didSet{ updateView() } } @IBInspectable var GradientSecondColor :UIColor = UIColor.clear { didSet{ updateView() } } @IBInspectable var useShadow:Bool = false { didSet{ if(useShadow){ dropShadow(scale: false) } } } @IBInspectable var shadowColor :UIColor = UIColor.blue { didSet{ if(useShadow){ dropShadow(scale: false) } } } @IBInspectable var shadowRadius:CGFloat = 0 { didSet{ if(useShadow){ dropShadow(scale: false) } } } @IBInspectable var radius:Bool = false { didSet{ updateRadius() } } @IBInspectable var ShadowX:Int = 1 { didSet{ updateRadius() } } @IBInspectable var ShadowY:Int = 1 { didSet{ updateRadius() } } @IBInspectable var radiusAmt:CGFloat = 0 { didSet{ updateRadius() } } override class var layerClass: Swift.AnyClass{ get { return CAGradientLayer.self } } func updateView(){ let layer = self.layer as! CAGradientLayer layer.colors = [GradientFirstColor.cgColor, GradientSecondColor.cgColor] } // OUTPUT 1 func dropShadow(scale: Bool = true) { self.layer.masksToBounds = false self.layer.shadowColor = shadowColor.cgColor self.layer.shadowOpacity = 0.3 self.layer.shadowOffset = CGSize(width: ShadowX, height: ShadowY) self.layer.shadowRadius = shadowRadius // self.layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath // self.layer.shouldRasterize = true // self.layer.rasterizationScale = scale ? UIScreen.main.scale : 1 } func updateRadius(){ if(radius){ self.layer.cornerRadius = radiusAmt; self.layer.shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: self.layer.cornerRadius).cgPath // self.layer.masksToBounds = true; } } } |