Skip to content

Instantly share code, notes, and snippets.

@shishirthedev
Created January 20, 2019 05:12
Show Gist options
  • Save shishirthedev/06951ade6cb607f1d5a1a5317f6f294d to your computer and use it in GitHub Desktop.
Save shishirthedev/06951ade6cb607f1d5a1a5317f6f294d to your computer and use it in GitHub Desktop.
import UIKit
@IBDesignable class CardView: UIView {
@IBInspectable var cornerradius:CGFloat = 4
@IBInspectable var shadowOffsetWidth:CGFloat = 0
@IBInspectable var shadowOffsetHeight:CGFloat = 3
@IBInspectable var shadowColor: UIColor = UIColor.gray
@IBInspectable var shadowOpacity: CGFloat = 0.3
@IBInspectable var borderWidth: CGFloat = 1
@IBInspectable var borderColor: UIColor = UIColor.clear
override func layoutSubviews() {
// Corner..............
layer.cornerRadius = cornerradius
// Shadow...........
layer.shadowColor = shadowColor.cgColor
layer.shadowOffset = CGSize(width: shadowOffsetWidth, height: shadowOffsetHeight)
let shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerradius)
layer.shadowPath = shadowPath.cgPath
layer.shadowOpacity = Float(shadowOpacity)
layer.masksToBounds = false
// Border.............
layer.borderWidth = borderWidth
layer.borderColor = borderColor.cgColor
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment