-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateBudgetModalViewController.swift
More file actions
126 lines (102 loc) · 4.4 KB
/
CreateBudgetModalViewController.swift
File metadata and controls
126 lines (102 loc) · 4.4 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
//
// CreateBudgetModalViewController.swift
// WalletWatcher
//
// Created by Mario Cordova on 6/18/17.
// Copyright © 2017 Mario Cordova. All rights reserved.
//
import UIKit
class CreateBudgetModalViewController: UIViewController, UITextFieldDelegate {
let budgetController = BudgetController.sharedInstance
let themeColor = UIColor(red: 28/255, green: 141/255, blue: 220/255, alpha: 1)
@IBOutlet var backgroundView: UIView! {
didSet {
backgroundView.backgroundColor = UIColor.black.withAlphaComponent(0.2)
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.regular)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = backgroundView.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
backgroundView.insertSubview(blurEffectView, at: 0)
}
}
@IBOutlet weak var createBudgetFormView: UIView! {
didSet {
createBudgetFormView.layer.backgroundColor = UIColor.white.cgColor
createBudgetFormView.layer.cornerRadius = 5.0
createBudgetFormView.layer.shadowOffset = CGSize(width: 5.0, height: 5.0)
createBudgetFormView.layer.shadowOpacity = 0.9
}
}
@IBOutlet weak var enterButton: UIButton! {
didSet {
enterButton.layer.borderWidth = 1.0
enterButton.layer.cornerRadius = 5.0
disableEnterButton(button: enterButton)
}
}
@IBOutlet weak var cancelButton: UIButton! {
didSet {
cancelButton.layer.borderWidth = 1.0
cancelButton.layer.cornerRadius = 5.0
cancelButton.layer.borderColor = themeColor.cgColor
cancelButton.setTitleColor(themeColor, for: .normal)
}
}
@IBOutlet var incomeField: UITextField! {
didSet {
incomeField.layer.borderWidth = 1.0
incomeField.layer.cornerRadius = 5.0
incomeField.layer.borderColor = UIColor.lightGray.cgColor
incomeField.attributedPlaceholder = NSAttributedString(string: incomeField.placeholder!, attributes: [NSForegroundColorAttributeName: UIColor.darkGray])
}
}
@IBOutlet var titleField: UITextField! {
didSet {
titleField.layer.borderWidth = 1.0
titleField.layer.cornerRadius = 5.0
titleField.layer.borderColor = UIColor.lightGray.cgColor
titleField.attributedPlaceholder = NSAttributedString(string: titleField.placeholder!, attributes: [NSForegroundColorAttributeName: UIColor.darkGray])
titleField.autocapitalizationType = .sentences
}
}
override func viewDidLoad() {
super.viewDidLoad()
incomeField.delegate = self
titleField.delegate = self
incomeField.addTarget(self, action: #selector(valueChanged(sender:)), for: .editingChanged)
titleField.addTarget(self, action: #selector(valueChanged(sender:)), for: .editingChanged)
titleField.becomeFirstResponder()
}
func valueChanged(sender: UITextField) {
if sender.text! != "" && !incomeField.text!.isEmpty && !titleField.text!.isEmpty {
enableEnterButton(button: enterButton)
} else {
disableEnterButton(button: enterButton)
}
}
func textFieldDidBeginEditing(_ textField: UITextField) {
textField.layer.borderColor = themeColor.cgColor
}
func textFieldDidEndEditing(_ textField: UITextField) {
textField.layer.borderColor = UIColor.lightGray.cgColor
}
func enableEnterButton(button: UIButton) {
button.isEnabled = true
button.layer.borderColor = themeColor.cgColor
button.setTitleColor(themeColor, for: .normal)
}
func disableEnterButton(button: UIButton) {
button.isEnabled = false
button.layer.borderColor = UIColor.lightGray.cgColor
button.setTitleColor(UIColor.lightGray, for: .normal)
}
@IBAction func enterTapped(_ sender: Any) {
view.endEditing(false)
budgetController.createBudget(title: titleField.text!, amount: incomeField.text!)
performSegue(withIdentifier: "unwindToMainViewFromBudget", sender: self)
}
@IBAction func cancelTapped(_ sender: Any) {
view.endEditing(false)
self.dismiss(animated: true, completion: nil)
}
}