Skip to content

Instantly share code, notes, and snippets.

@NikhilManapure
Created October 12, 2017 08:48
Show Gist options
  • Select an option

  • Save NikhilManapure/56619d762a061fdd5e357cf1e82a0149 to your computer and use it in GitHub Desktop.

Select an option

Save NikhilManapure/56619d762a061fdd5e357cf1e82a0149 to your computer and use it in GitHub Desktop.

Revisions

  1. NikhilManapure created this gist Oct 12, 2017.
    18 changes: 18 additions & 0 deletions CornerRadiusWithShadowView.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    class CornerRadiusWithShadowView: UIView {
    var cornerRadius: CGFloat = 2.0
    var shadowOffsetWidth: Double = 0.0
    var shadowOffsetHeight: Double = 3.0
    var shadowColor: UIColor = .black
    var shadowOpacity: Float = 0.5

    override func layoutSubviews() {
    super.layoutSubviews()
    layer.cornerRadius = cornerRadius
    layer.masksToBounds = false
    layer.shadowColor = shadowColor.cgColor
    layer.shadowOffset = CGSize(width: shadowOffsetWidth, height: shadowOffsetHeight)
    layer.shadowOpacity = shadowOpacity
    let shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius)
    layer.shadowPath = shadowPath.cgPath
    }
    }