-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToastView.swift
More file actions
88 lines (72 loc) · 2.31 KB
/
ToastView.swift
File metadata and controls
88 lines (72 loc) · 2.31 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
85
86
87
88
//
// ToastView.swift
// Presentation
//
// Created by 최정인 on 9/2/25.
//
import SnapKit
import UIKit
final class ToastView: UIView {
private enum Layout {
static let horizontalMargin: CGFloat = 16
static let checkIconSize: CGFloat = 24
static let messageLabelLeadingSpacing: CGFloat = 8
}
private let checkIcon = UIImageView()
private let messageLabel = UILabel()
private var message: String
init(message: String) {
self.message = message
super.init(frame: .zero)
configureAttribute()
configureLayout()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func configureAttribute() {
alpha = 0
isHidden = true
layer.masksToBounds = true
layer.cornerRadius = 12
backgroundColor = BitnagilColor.gray30
checkIcon.image = BitnagilIcon.orangeCheckedCircleIcon
messageLabel.text = message
messageLabel.font = BitnagilFont(style: .body2, weight: .medium).font
messageLabel.textColor = .white
}
private func configureLayout() {
addSubview(checkIcon)
addSubview(messageLabel)
checkIcon.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.leading.equalToSuperview().offset(Layout.horizontalMargin)
make.size.equalTo(Layout.checkIconSize)
}
messageLabel.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.leading.equalTo(checkIcon.snp.trailing).offset(Layout.messageLabelLeadingSpacing)
make.trailing.equalToSuperview().offset(-Layout.horizontalMargin)
}
}
func showToastMessageView(message: String? = nil) {
if let message {
self.message = message
self.messageLabel.text = message
}
alpha = 0
isHidden = false
UIView.animate(withDuration: 0.35, delay: 0.01) {
self.alpha = 1
} completion: { [weak self] _ in
self?.hideToastMessageView()
}
}
private func hideToastMessageView() {
UIView.animate(withDuration: 0.35, delay: 2.0) {
self.alpha = 0
} completion: { _ in
self.isHidden = true
}
}
}