-
Notifications
You must be signed in to change notification settings - Fork 2
/
ViewController.swift
149 lines (84 loc) · 4.43 KB
/
ViewController.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
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
// var bgColor = UIColor()
//var textColor = UIColor()
@IBAction func askBAction(_ sender: UIButton) {
alertController()
}
@IBOutlet weak var askBOutlet: UIButton!
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var settingsButtonOutlet: UIButton!
@IBOutlet weak var label: UILabel!
@IBAction func settingsButton(_ sender: UIButton) {
colorsCheck()
// checkTFAndUseSegue()
}
override func viewDidLoad() {
super.viewDidLoad()
self.textField.delegate = self
/*
view.backgroundColor = #colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1)
label.textColor = UIColor.white
settingsButtonOutlet.tintColor = UIColor.white
askBOutlet.titleLabel?.textColor = UIColor.white
*/
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
askBOutlet.accessibilityActivate()
return true
}
override var prefersStatusBarHidden: Bool {
return true
}
// кастомизация
func colorsCheck() {
if view.backgroundColor == UIColor.white {
view.backgroundColor = #colorLiteral(red: 0, green: 0.4367694855, blue: 0.4325060546, alpha: 1)
label.textColor = UIColor.white
settingsButtonOutlet.tintColor = UIColor.white
askBOutlet.titleLabel?.textColor = UIColor.white
} else if view.backgroundColor == #colorLiteral(red: 0, green: 0.4367694855, blue: 0.4325060546, alpha: 1) {
view.backgroundColor = #colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1)
// askBOutlet.titleLabel?.textColor = UIColor.white
} else if view.backgroundColor == #colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1) {
view.backgroundColor = #colorLiteral(red: 0.8905699253, green: 0.5546572804, blue: 0.451649785, alpha: 1)
askBOutlet.titleLabel?.textColor = UIColor.white
} else if view.backgroundColor == #colorLiteral(red: 0.8905699253, green: 0.5546572804, blue: 0.451649785, alpha: 1) {
view.backgroundColor = UIColor.white
label.textColor = UIColor.black
settingsButtonOutlet.tintColor = UIColor.black
askBOutlet.tintColor = UIColor.black
askBOutlet.titleLabel?.textColor = UIColor.black
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let dvc = segue.destination as! SecondViewController
if textField.text != "" {
// передача текста лейблу второго вьюконтроллера
dvc.myString = textField.text!
// передача цвета вью второму вью контроллеру
dvc.bgColor = view.backgroundColor!
dvc.textColor = label.textColor
} else {
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
self.view.endEditing(true)
}
// Проверка на заполняемость поля и алерт, если не заполнено
func alertController() {
if textField.text == "" {
let alertController = UIAlertController(title: "The field is empty", message: "Please, enter text in the field", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(action)
present(alertController, animated: true)
}
}
// проверка на заполненнность и переход по сегвыю
func checkTFAndUseSegue() {
if textField.text != "" {
performSegue(withIdentifier: "segue", sender: self)
}
}
}