Commit 591f6b74 authored by tybrandt's avatar tybrandt
Browse files

Designed the Add Transaction view

parent c07b4142
File added
BTIcon.jpg

39.3 KB

......@@ -7,14 +7,109 @@
import UIKit
class AddTransactionViewController: UIViewController {
class AddTransactionViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var addButton: UIBarButtonItem!
@IBOutlet weak var categoryTextField: UITextField!
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var costTextField: UITextField!
var doneButton: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
addButton.isEnabled = false
categoryTextField.delegate = self
nameTextField.delegate = self
costTextField.delegate = self
addDoneButtonToKeyboard(myAction: #selector(costTextField.resignFirstResponder))
NotificationCenter.default.addObserver(self,
selector: #selector(AddTransactionViewController.keyboardWillShow),
name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(AddTransactionViewController.keyboardWillHide),
name: UIResponder.keyboardWillHideNotification, object: nil)
}
@IBAction func addTransactions(_ sender: UIBarButtonItem) {
dismiss(animated: true, completion: nil)
}
@IBAction func cancel(_ sender: UIButton) {
@IBAction func cancel(_ sender: UIBarButtonItem) {
dismiss(animated: true, completion: nil)
}
func textFieldDidBeginEditing(_ textField: UITextField) {
addButton.isEnabled = false
}
func textFieldDidChangeSelection(_ textField: UITextField) {
let text = costTextField.text ?? ""
if text.isEmpty {
doneButton.isEnabled = false
} else {
doneButton.isEnabled = true
}
}
func textFieldDidEndEditing(_ textField: UITextField) {
updateAddButtonStatus()
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
categoryTextField.resignFirstResponder()
nameTextField.resignFirstResponder()
return true
}
private func updateAddButtonStatus() {
var text = categoryTextField.text ?? ""
if text.isEmpty {
addButton.isEnabled = false
return
}
text = nameTextField.text ?? ""
if text.isEmpty {
addButton.isEnabled = false
return
}
text = costTextField.text ?? ""
if text.isEmpty {
addButton.isEnabled = false
return
}
addButton.isEnabled = true
}
private func addDoneButtonToKeyboard(myAction:Selector?){
let doneToolbar: UIToolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 300, height: 40))
doneToolbar.barStyle = UIBarStyle.default
let flexSpace = UIBarButtonItem(barButtonSystemItem:
UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
doneButton = UIBarButtonItem(
title: "Done", style: UIBarButtonItem.Style.done, target: costTextField, action: myAction)
doneButton.isEnabled = false
var items = [UIBarButtonItem]()
items.append(flexSpace)
items.append(doneButton)
doneToolbar.items = items
doneToolbar.sizeToFit()
costTextField.inputAccessoryView = doneToolbar
}
@objc func keyboardWillShow(notification: NSNotification) {
guard let userInfo = notification.userInfo else {return}
guard let keyboardSize = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else {return}
let keyboardFrame = keyboardSize.cgRectValue
if costTextField.isEditing && costTextField.frame.origin.y + costTextField.frame.height
> self.view.frame.height - keyboardFrame.height {
self.view.frame.origin.y = -costTextField.frame.origin.y - costTextField.frame.height
+ self.view.frame.height - keyboardFrame.height - 20
}
}
@objc func keyboardWillHide(notification: NSNotification) {
if self.view.frame.origin.y != 0 {
self.view.frame.origin.y = 0
}
}
}
{
"images" : [
{
"filename" : "Icon-App-40x40@1x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "Icon-App-20x20@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"filename" : "Icon-App-29x29@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "Icon-App-29x29@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"filename" : "Icon-App-40x40@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "Icon-App-40x40@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"filename" : "Icon-App-60x60@2x.png",
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"filename" : "Icon-App-60x60@3x.png",
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"filename" : "Icon-App-20x20@1x.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"filename" : "Icon-App-20x20@2x.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "Icon-App-29x29@1x.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"filename" : "Icon-App-29x29@2x-1.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "Icon-App-40x40@1x-1.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"filename" : "Icon-App-40x40@2x-1.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "Icon-App-76x76@1x.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"filename" : "Icon-App-76x76@2x.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"filename" : "Icon-App-83.5x83.5@2x.png",
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"filename" : "ItunesArtwork@2x.png",
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment