-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfettiToastView.swift
59 lines (46 loc) · 1.77 KB
/
ConfettiToastView.swift
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
//
// ConfettiToastView.swift
// ConfettiToastExample
//
// Created by Miles Vinson on 7/11/21.
//
import UIKit
class ConfettiToastView: UIView {
private let confettiCircle = ConfettiCircle()
private let label = UILabel()
init() {
super.init(frame: .zero)
self.backgroundColor = UIColor.systemBlue
self.layer.cornerRadius = 16
self.layer.cornerCurve = .continuous
self.layer.shadowColor = UIColor.systemBlue.cgColor
self.layer.shadowOffset = CGSize(width: 0, height: 6)
self.layer.shadowOpacity = 0.25
self.layer.shadowRadius = 14
addSubview(confettiCircle)
confettiCircle.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
confettiCircle.leftAnchor.constraint(equalTo: leftAnchor, constant: 16),
confettiCircle.centerYAnchor.constraint(equalTo: centerYAnchor),
confettiCircle.heightAnchor.constraint(equalToConstant: 38),
confettiCircle.widthAnchor.constraint(equalToConstant: 38)
])
label.text = "Success!"
label.font = UIFont.systemFont(ofSize: 17)
label.textColor = UIColor.white
addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
label.leftAnchor.constraint(equalTo: confettiCircle.rightAnchor, constant: 16),
label.centerYAnchor.constraint(equalTo: centerYAnchor)
])
}
public func animate() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.confettiCircle.animate()
}
}
required init?(coder aDecoder: NSCoder) {
fatalError()
}
}