-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleCode.swift
162 lines (129 loc) · 6.19 KB
/
SampleCode.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// MNkAlertView_comp.swift
// MNkSupportUtilities_Example
//
// Created by Malith Kamburapola on 2022-01-11.
// Copyright © 2022 CocoaPods. All rights reserved.
//
import UIKit
class MNkAlertView_Sample: UIViewController {
private lazy var showButton: UIButton = {
let btn = UIButton()
btn.setTitle("Show", for: .normal)
btn.backgroundColor = .white
btn.setTitleColor(.black, for: .normal)
btn.translatesAutoresizingMaskIntoConstraints = false
btn.layer.cornerRadius = 3
btn.addTarget(self, action: #selector(didTapShowButton), for: .touchUpInside)
return btn
}()
private func insertAndLayoutSubviews() {
view.addSubview(showButton)
NSLayoutConstraint.activate([showButton.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
showButton.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
showButton.heightAnchor.constraint(equalToConstant: 50),
showButton.widthAnchor.constraint(equalToConstant: 100)])
}
private func config() {
super.config()
view.backgroundColor = .green
}
@objc private func didTapShowButton() {
showAlert()
// showCustomAlert()
}
private func showAlert() {
let alertView = MNkAlertView()
alertView.titleLabel.text = "Confirm"
alertView.messageLabel.text = "Do you want to proceed with these settings?"
alertView.type = .multi
alertView.action = { actionType, data in
switch actionType {
case .rightClick:
print("Right Action")
case .leftClick:
print("Left Action")
default:
break
}
}
let alertController = MNkAlertViewController()
alertController.set(alertView: alertView)
self.showAlert(of: alertController, aditional: nil)
}
private func showCustomAlert() {
let alertView = CustomAlertView()
alertView.titleLabel.text = "Saved"
alertView.messageLabel.text = "New settings save successfully."
alertView.action = { actionType, data in
switch actionType {
case .rightClick:
print("Right Action")
case .leftClick:
print("Left Action")
default:
break
}
}
let alertController = MNkAlertViewController()
alertController.set(alertView: alertView)
self.showAlert(of: alertController, aditional: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
insertAndLayoutSubviews()
config()
}
}
//MARK: - CUSTOM ALERT VIEW
class CustomAlertView: MNkAlertView {
private var topStripView: UIView = {
let view = UIView()
view.backgroundColor = .lightBlue
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
private var indicatorImageView: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFit
iv.image = .gearRoundFill
iv.translatesAutoresizingMaskIntoConstraints = false
return iv
}()
override func createViews() {
super.createViews()
mainStackView.insertArrangedSubview(indicatorImageView, at: 0)
mainStackView.spacing = 20
rightActionButton.layer.cornerRadius = 3
rightActionButton.backgroundColor = .lightBlue
rightActionButton.setTitleColor(.white, for: .normal)
}
override func insertAndLayoutSubviews() {
self.addSubview(alertContainer)
alertContainer.addSubview(mainStackView)
NSLayoutConstraint.activate([mainStackView.leadingAnchor.constraint(equalTo: alertContainer.leadingAnchor),
mainStackView.trailingAnchor.constraint(equalTo: alertContainer.trailingAnchor),
mainStackView.topAnchor.constraint(equalTo: alertContainer.topAnchor,
constant: 20),
mainStackView.bottomAnchor.constraint(equalTo: alertContainer.bottomAnchor,
constant: -20)])
NSLayoutConstraint.activate([alertContainer.centerXAnchor.constraint(equalTo: self.centerXAnchor),
alertContainer.centerYAnchor.constraint(equalTo: self.centerYAnchor),
alertContainer.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.8),
alertContainer.heightAnchor.constraint(greaterThanOrEqualToConstant: 150)])
NSLayoutConstraint.activate([titleLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: 30),
titleLabel.widthAnchor.constraint(equalTo: alertContainer.widthAnchor, multiplier: 0.88),
messageLabel.widthAnchor.constraint(equalTo: alertContainer.widthAnchor, multiplier: 0.88),
buttonStackview.widthAnchor.constraint(equalTo: alertContainer.widthAnchor, multiplier: 0.6)])
NSLayoutConstraint.activate([indicatorImageView.widthAnchor.constraint(equalToConstant: 80),
indicatorImageView.heightAnchor.constraint(equalTo: indicatorImageView.widthAnchor)])
alertContainer.addSubview(topStripView)
NSLayoutConstraint.activate([topStripView.topAnchor.constraint(equalTo: alertContainer.topAnchor),
topStripView.leadingAnchor.constraint(equalTo: alertContainer.leadingAnchor),
topStripView.trailingAnchor.constraint(equalTo: alertContainer.trailingAnchor),
topStripView.heightAnchor.constraint(equalToConstant: 5)])
}
override func config() {
backgroundColor = .clear
}
}