-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.swift
More file actions
84 lines (63 loc) · 2.18 KB
/
Copy pathButton.swift
File metadata and controls
84 lines (63 loc) · 2.18 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Button.swift
// ImpactHub
//
// Created by Niklas on 17/05/2017.
// Copyright © 2017 Lightful Ltd. All rights reserved.
//
import UIKit
class Button: UIButton {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.adjustsImageWhenHighlighted = false
}
override var isEnabled: Bool {
didSet {
switch isEnabled {
case true:
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseInOut, animations: {
self.alpha = 1.0
}, completion: nil)
case false:
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseInOut, animations: {
self.alpha = 0.5
}, completion: nil)
}
}
}
override var isHighlighted: Bool {
didSet {
if isHighlighted {
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseInOut, animations: {
self.transform = CGAffineTransform.init(scaleX: 0.95, y: 0.95)
self.alpha = 0.9
}, completion: nil)
}
else {
UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseInOut, animations: {
self.transform = CGAffineTransform.identity
self.alpha = 1.0
}, completion: nil)
}
}
}
var didLayout = false
override func layoutSubviews() {
super.layoutSubviews()
if didLayout {
return
}
didLayout = true
self.layer.cornerRadius = self.frame.height / 2
addShadow()
}
func addShadow() {
self.layer.shadowColor = UIColor(hexString: "D5D5D5").cgColor
self.layer.shadowOffset = CGSize(width: 0, height: 5)
self.layer.shadowOpacity = 0.97
self.layer.shadowPath = UIBezierPath(rect: self.layer.bounds).cgPath
self.layer.shadowRadius = 15.0
self.layer.shouldRasterize = true
self.layer.rasterizationScale = UIScreen.main.scale
}
}