-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
149 lines (107 loc) · 5.83 KB
/
ViewController.swift
File metadata and controls
149 lines (107 loc) · 5.83 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
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
//
// ViewController.swift
// TSAlertController
//
// Created by rlarjsdn3 on 01/13/2025.
// Copyright (c) 2025 rlarjsdn3. All rights reserved.
//
import UIKit
import TSAlertController
class ViewController: UIViewController {
@IBOutlet weak var alertStack: UIStackView!
@IBOutlet weak var actionSheetStack: UIStackView!
// MARK: - Alert ①
@IBAction func showBasicAlert(_ sender: Any) {
let alert = TSAlertController(title: "Current Location Not Available",
message: "Your current location can't be determined at this time.",
preferredStyle: .alert)
let okAction = TSAlertAction(title: "OK", style: .default)
okAction.configuration.backgroundColor = .systemBlue
okAction.configuration.titleAttributes = [.font: UIFont.preferredFont(forTextStyle: .headline),
.foregroundColor: UIColor.alertWhite]
alert.addAction(okAction)
present(alert, animated: true)
}
// MARK: - Alert ②
@IBAction func showAlertWithTextfields(_ sender: Any) {
let alert = TSAlertController(title: "Sign In",
message: "Please enter your username and password to access your account.",
options: [.dismissOnTapOutside],
preferredStyle: .alert)
let okAction = TSAlertAction(title: "Sign In", style: .default)
alert.addAction(okAction)
alert.preferredAction = okAction
let cancelAction = TSAlertAction(title: "Cancel", style: .cancel)
cancelAction.configuration.backgroundColor = .systemBlue
cancelAction.configuration.titleAttributes = [.font: UIFont.preferredFont(forTextStyle: .headline),
.foregroundColor: UIColor.alertWhite]
alert.addAction(cancelAction)
alert.addTextField { textfield in
textfield.placeholder = "Username"
textfield.returnKeyType = .next
}
alert.addTextField { textfield in
textfield.placeholder = "Password"
textfield.isSecureTextEntry = true
textfield.returnKeyType = .done
}
present(alert, animated: true)
}
// MARK: - ActionSheet ①
@IBAction func showBasicActionSheet(_ sender: Any) {
let marketCap = MarketCapView()
let actionSheet = TSAlertController(marketCap,
options: [.dismissOnSwipeDown, .interactiveScaleAndDrag],
preferredStyle: .floatingSheet)
actionSheet.configuration.headerAnimation = .slideUp
actionSheet.configuration.buttonGroupAnimation = .fadeIn
let okAction = TSAlertAction(title: "Confirm")
okAction.configuration.backgroundColor = .systemBlue
okAction.configuration.titleAttributes = [.font: UIFont.preferredFont(forTextStyle: .headline),
.foregroundColor: UIColor.alertWhite]
actionSheet.addAction(okAction)
present(actionSheet, animated: true)
}
// MARK: - ActionSheet ②
@IBAction func showActionSheetWithVariousAppearance(_ sender: Any) {
let actionSheet = TSAlertController(title: "What kind of inquiry do you have?",
options: [.stretchyDragging, .dismissOnSwipeDown],
preferredStyle: .actionSheet)
actionSheet.viewConfiguration.margin = .init(buttonLeft: 5, buttonRight: 5)
let config = TSButton.Configuration(imageSpacing: 15,
preferredSymbolConfigurationForImage: .init(paletteColors: [.label]),
accessoryImage: UIImage(systemName: "chevron.right"),
preferredSymbolConfigurationForAccessoryImage: .init(paletteColors: [.label]),
contentAlignment: .left,
backgroundColor: .clear)
let appUsageInquiry = TSAlertAction(title: "App Usage Inquiry")
appUsageInquiry.configuration = config
appUsageInquiry.configuration.image = UIImage(systemName: "app")
appUsageInquiry.highlightType = .tintAndScaleDown(color: .systemGray4)
actionSheet.addAction(appUsageInquiry)
let paymentIssue = TSAlertAction(title: "Payment Issues")
paymentIssue.configuration = config
paymentIssue.configuration.imageSpacing = 10
paymentIssue.configuration.image = UIImage(systemName: "creditcard.fill")
paymentIssue.highlightType = .tintAndScaleDown(color: .systemGray4)
actionSheet.addAction(paymentIssue)
let accountSupport = TSAlertAction(title: "Account & Login Issues")
accountSupport.configuration = config
accountSupport.configuration.image = UIImage(systemName: "person.crop.circle")
accountSupport.highlightType = .tintAndScaleDown(color: .systemGray4)
actionSheet.addAction(accountSupport)
let bugReport = TSAlertAction(title: "Bug Report")
bugReport.configuration = config
bugReport.configuration.image = UIImage(systemName: "ladybug")
bugReport.highlightType = .tintAndScaleDown(color: .systemGray4)
actionSheet.addAction(bugReport)
present(actionSheet, animated: true)
}
}
// MARK: - Lifecycle
extension ViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .systemBackground
}
}