-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardView.swift
More file actions
61 lines (48 loc) · 1.45 KB
/
CardView.swift
File metadata and controls
61 lines (48 loc) · 1.45 KB
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
//
// CardView.swift
//
// Created by Arshad Parwez on 25/11/16.
// Copyright © 2016 Arshad Parwez. All rights reserved.
//
import Foundation
import UIKit
@IBDesignable
class CardView: UIView {
@IBInspectable var shadowOffsetWidth: Int = 0
@IBInspectable var shadowOffsetHeight: Int = 3
@IBInspectable var cornerRadius: CGFloat = 2 {
didSet {
layer.cornerRadius = cornerRadius
}
}
@IBInspectable var shadowColor: UIColor? {
didSet {
layer.shadowColor = shadowColor?.cgColor
}
}
@IBInspectable var shadowOpacity: Float? {
didSet {
layer.shadowOpacity = shadowOpacity!
}
}
@IBInspectable var borderWidth: CGFloat = 0.5 {
didSet {
layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.cgColor
}
}
override func layoutSubviews() {
layer.borderWidth = 0.5
layer.borderColor = UIColor.lightGray.cgColor
let shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius)
layer.masksToBounds = false
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 0.5
layer.shadowOffset = CGSize(width: shadowOffsetWidth, height: shadowOffsetHeight);
layer.shadowPath = shadowPath.cgPath
}
}