From 380ebcbacabce90746298e0cbda73d7006c90036 Mon Sep 17 00:00:00 2001 From: Paco Chacon Date: Sun, 11 Feb 2018 02:10:08 -0600 Subject: [PATCH 1/6] Added Sign up view and controller, also test files --- PowerHome.xcodeproj/project.pbxproj | 16 +++++++++++++ PowerHome/SignUpView.swift | 21 +++++++++++++++++ PowerHome/SignUpViewController.swift | 35 ++++++++++++++++++++++++++++ PowerHomeTests/LoginTests.swift | 35 ++++++++++++++++++++++++++++ PowerHomeTests/SignUpTests.swift | 35 ++++++++++++++++++++++++++++ 5 files changed, 142 insertions(+) create mode 100644 PowerHome/SignUpView.swift create mode 100644 PowerHome/SignUpViewController.swift create mode 100644 PowerHomeTests/LoginTests.swift create mode 100644 PowerHomeTests/SignUpTests.swift diff --git a/PowerHome.xcodeproj/project.pbxproj b/PowerHome.xcodeproj/project.pbxproj index b88350a..5cc49b9 100644 --- a/PowerHome.xcodeproj/project.pbxproj +++ b/PowerHome.xcodeproj/project.pbxproj @@ -8,6 +8,10 @@ /* Begin PBXBuildFile section */ ACCC0D4F20301DF10035F967 /* UISquareButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D4E20301DF10035F967 /* UISquareButton.swift */; }; + ACCC0D512030312B0035F967 /* SignUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D502030312B0035F967 /* SignUpViewController.swift */; }; + ACCC0D53203031410035F967 /* SignUpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D52203031410035F967 /* SignUpView.swift */; }; + ACCC0D55203031A70035F967 /* LoginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D54203031A70035F967 /* LoginTests.swift */; }; + ACCC0D57203031BB0035F967 /* SignUpTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D56203031BB0035F967 /* SignUpTests.swift */; }; ACFC97BD202FA648004A3FE3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97BC202FA648004A3FE3 /* AppDelegate.swift */; }; ACFC97C4202FA648004A3FE3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ACFC97C3202FA648004A3FE3 /* Assets.xcassets */; }; ACFC97C7202FA648004A3FE3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ACFC97C5202FA648004A3FE3 /* LaunchScreen.storyboard */; }; @@ -37,6 +41,10 @@ /* Begin PBXFileReference section */ ACCC0D4E20301DF10035F967 /* UISquareButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UISquareButton.swift; sourceTree = ""; }; + ACCC0D502030312B0035F967 /* SignUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = ""; }; + ACCC0D52203031410035F967 /* SignUpView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpView.swift; sourceTree = ""; }; + ACCC0D54203031A70035F967 /* LoginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginTests.swift; sourceTree = ""; }; + ACCC0D56203031BB0035F967 /* SignUpTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpTests.swift; sourceTree = ""; }; ACFC97B9202FA648004A3FE3 /* PowerHome.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PowerHome.app; sourceTree = BUILT_PRODUCTS_DIR; }; ACFC97BC202FA648004A3FE3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; ACFC97C3202FA648004A3FE3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -124,6 +132,8 @@ ACFC97D0202FA648004A3FE3 /* PowerHomeTests */ = { isa = PBXGroup; children = ( + ACCC0D56203031BB0035F967 /* SignUpTests.swift */, + ACCC0D54203031A70035F967 /* LoginTests.swift */, ACFC97D1202FA648004A3FE3 /* PowerHomeTests.swift */, ACFC97D3202FA648004A3FE3 /* Info.plist */, ); @@ -143,6 +153,7 @@ isa = PBXGroup; children = ( ACFC97EE202FCF9F004A3FE3 /* LoginView.swift */, + ACCC0D52203031410035F967 /* SignUpView.swift */, ); name = Views; sourceTree = ""; @@ -151,6 +162,7 @@ isa = PBXGroup; children = ( ACFC97EA202FC889004A3FE3 /* LoginViewController.swift */, + ACCC0D502030312B0035F967 /* SignUpViewController.swift */, ); name = Controllers; sourceTree = ""; @@ -296,8 +308,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + ACCC0D512030312B0035F967 /* SignUpViewController.swift in Sources */, ACFC97EF202FCF9F004A3FE3 /* LoginView.swift in Sources */, ACFC97F2202FD0CD004A3FE3 /* Colors.swift in Sources */, + ACCC0D53203031410035F967 /* SignUpView.swift in Sources */, ACFC97EB202FC889004A3FE3 /* LoginViewController.swift in Sources */, ACFC97BD202FA648004A3FE3 /* AppDelegate.swift in Sources */, ACCC0D4F20301DF10035F967 /* UISquareButton.swift in Sources */, @@ -309,6 +323,8 @@ buildActionMask = 2147483647; files = ( ACFC97D2202FA648004A3FE3 /* PowerHomeTests.swift in Sources */, + ACCC0D57203031BB0035F967 /* SignUpTests.swift in Sources */, + ACCC0D55203031A70035F967 /* LoginTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PowerHome/SignUpView.swift b/PowerHome/SignUpView.swift new file mode 100644 index 0000000..7b1a7a7 --- /dev/null +++ b/PowerHome/SignUpView.swift @@ -0,0 +1,21 @@ +// +// SignUpView.swift +// PowerHome +// +// Created by Francisco Javier Chacon de Dios on 11/02/18. +// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. +// + +import UIKit + +class SignUpView: UIView { + + /* + // Only override draw() if you perform custom drawing. + // An empty implementation adversely affects performance during animation. + override func draw(_ rect: CGRect) { + // Drawing code + } + */ + +} diff --git a/PowerHome/SignUpViewController.swift b/PowerHome/SignUpViewController.swift new file mode 100644 index 0000000..043d9ae --- /dev/null +++ b/PowerHome/SignUpViewController.swift @@ -0,0 +1,35 @@ +// +// SignUpViewController.swift +// PowerHome +// +// Created by Francisco Javier Chacon de Dios on 11/02/18. +// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. +// + +import UIKit + +class SignUpViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destinationViewController. + // Pass the selected object to the new view controller. + } + */ + +} diff --git a/PowerHomeTests/LoginTests.swift b/PowerHomeTests/LoginTests.swift new file mode 100644 index 0000000..9a0356c --- /dev/null +++ b/PowerHomeTests/LoginTests.swift @@ -0,0 +1,35 @@ +// +// LoginTests.swift +// PowerHomeTests +// +// Created by Francisco Javier Chacon de Dios on 11/02/18. +// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. +// + +import XCTest + +class LoginTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/PowerHomeTests/SignUpTests.swift b/PowerHomeTests/SignUpTests.swift new file mode 100644 index 0000000..cf27375 --- /dev/null +++ b/PowerHomeTests/SignUpTests.swift @@ -0,0 +1,35 @@ +// +// SignUpTests.swift +// PowerHomeTests +// +// Created by Francisco Javier Chacon de Dios on 11/02/18. +// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. +// + +import XCTest + +class SignUpTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} From d275c99021360e0bcce80c25d6b575a778459de4 Mon Sep 17 00:00:00 2001 From: Paco Chacon Date: Sun, 11 Feb 2018 02:10:31 -0600 Subject: [PATCH 2/6] Deleted unused code --- PowerHome/SignUpView.swift | 8 -------- PowerHome/SignUpViewController.swift | 16 ---------------- 2 files changed, 24 deletions(-) diff --git a/PowerHome/SignUpView.swift b/PowerHome/SignUpView.swift index 7b1a7a7..028f5b7 100644 --- a/PowerHome/SignUpView.swift +++ b/PowerHome/SignUpView.swift @@ -10,12 +10,4 @@ import UIKit class SignUpView: UIView { - /* - // Only override draw() if you perform custom drawing. - // An empty implementation adversely affects performance during animation. - override func draw(_ rect: CGRect) { - // Drawing code - } - */ - } diff --git a/PowerHome/SignUpViewController.swift b/PowerHome/SignUpViewController.swift index 043d9ae..060453a 100644 --- a/PowerHome/SignUpViewController.swift +++ b/PowerHome/SignUpViewController.swift @@ -16,20 +16,4 @@ class SignUpViewController: UIViewController { // Do any additional setup after loading the view. } - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destinationViewController. - // Pass the selected object to the new view controller. - } - */ - } From 0d062a3e1b744ee0b7aca6614b7029eba7f50f33 Mon Sep 17 00:00:00 2001 From: Paco Chacon Date: Sun, 11 Feb 2018 02:25:05 -0600 Subject: [PATCH 3/6] Increase LoginViewController code coverage --- PowerHome.xcodeproj/project.pbxproj | 4 ---- PowerHomeTests/LoginTests.swift | 32 +++++++++++++++++----------- PowerHomeTests/PowerHomeTests.swift | 33 ----------------------------- 3 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 PowerHomeTests/PowerHomeTests.swift diff --git a/PowerHome.xcodeproj/project.pbxproj b/PowerHome.xcodeproj/project.pbxproj index 5cc49b9..e2c4913 100644 --- a/PowerHome.xcodeproj/project.pbxproj +++ b/PowerHome.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ ACFC97BD202FA648004A3FE3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97BC202FA648004A3FE3 /* AppDelegate.swift */; }; ACFC97C4202FA648004A3FE3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ACFC97C3202FA648004A3FE3 /* Assets.xcassets */; }; ACFC97C7202FA648004A3FE3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ACFC97C5202FA648004A3FE3 /* LaunchScreen.storyboard */; }; - ACFC97D2202FA648004A3FE3 /* PowerHomeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97D1202FA648004A3FE3 /* PowerHomeTests.swift */; }; ACFC97DD202FA649004A3FE3 /* PowerHomeUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97DC202FA649004A3FE3 /* PowerHomeUITests.swift */; }; ACFC97EB202FC889004A3FE3 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97EA202FC889004A3FE3 /* LoginViewController.swift */; }; ACFC97EF202FCF9F004A3FE3 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97EE202FCF9F004A3FE3 /* LoginView.swift */; }; @@ -51,7 +50,6 @@ ACFC97C6202FA648004A3FE3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; ACFC97C8202FA648004A3FE3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; ACFC97CD202FA648004A3FE3 /* PowerHomeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PowerHomeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - ACFC97D1202FA648004A3FE3 /* PowerHomeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PowerHomeTests.swift; sourceTree = ""; }; ACFC97D3202FA648004A3FE3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; ACFC97D8202FA649004A3FE3 /* PowerHomeUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PowerHomeUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; ACFC97DC202FA649004A3FE3 /* PowerHomeUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PowerHomeUITests.swift; sourceTree = ""; }; @@ -134,7 +132,6 @@ children = ( ACCC0D56203031BB0035F967 /* SignUpTests.swift */, ACCC0D54203031A70035F967 /* LoginTests.swift */, - ACFC97D1202FA648004A3FE3 /* PowerHomeTests.swift */, ACFC97D3202FA648004A3FE3 /* Info.plist */, ); path = PowerHomeTests; @@ -322,7 +319,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - ACFC97D2202FA648004A3FE3 /* PowerHomeTests.swift in Sources */, ACCC0D57203031BB0035F967 /* SignUpTests.swift in Sources */, ACCC0D55203031A70035F967 /* LoginTests.swift in Sources */, ); diff --git a/PowerHomeTests/LoginTests.swift b/PowerHomeTests/LoginTests.swift index 9a0356c..d7cb001 100644 --- a/PowerHomeTests/LoginTests.swift +++ b/PowerHomeTests/LoginTests.swift @@ -7,29 +7,37 @@ // import XCTest +@testable import PowerHome class LoginTests: XCTestCase { - + + var loginViewController: LoginViewController? override func setUp() { super.setUp() + + loginViewController = LoginViewController() + + _ = loginViewController?.view // Put setup code here. This method is called before the invocation of each test method in the class. } override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() + loginViewController = nil } - - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. + + func loginViewControllerInitializesProperly() { + loginViewController?.loginView.dismissKeyboard(Any.self) + XCTAssertNotNil(loginViewController) } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measure { - // Put the code you want to measure the time of here. - } + + func testConformsUITextFieldDelegateProtocolShouldBeTrue() { + XCTAssert((loginViewController?.loginView.conforms(to: UITextFieldDelegate.self))!) } - + + func testTextFieldShouldReturnTrueValue() { + XCTAssert((loginViewController?.loginView.textFieldShouldReturn(UITextField()))!) + } + } diff --git a/PowerHomeTests/PowerHomeTests.swift b/PowerHomeTests/PowerHomeTests.swift deleted file mode 100644 index 27a50d6..0000000 --- a/PowerHomeTests/PowerHomeTests.swift +++ /dev/null @@ -1,33 +0,0 @@ -// -// PowerHomeTests.swift -// PowerHomeTests -// -// Created by Francisco Javier Chacon de Dios on 10/02/18. -// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. -// - -import XCTest -@testable import PowerHome - -class PowerHomeTests: XCTestCase { - - var loginViewController: LoginViewController? - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - - loginViewController = LoginViewController() - - _ = loginViewController?.view - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testViewControllerInitializesProperly() { - XCTAssertNotNil(loginViewController) - } - -} From 0dcebab70230819bd1c2dd5ab4a93e60358c7cd2 Mon Sep 17 00:00:00 2001 From: Paco Chacon Date: Sun, 11 Feb 2018 02:39:58 -0600 Subject: [PATCH 4/6] Added BaseView to set delegates and shared functions --- PowerHome.xcodeproj/project.pbxproj | 4 ++++ PowerHome/BaseView.swift | 34 +++++++++++++++++++++++++++++ PowerHome/LoginView.swift | 15 +------------ 3 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 PowerHome/BaseView.swift diff --git a/PowerHome.xcodeproj/project.pbxproj b/PowerHome.xcodeproj/project.pbxproj index e2c4913..a1f51a2 100644 --- a/PowerHome.xcodeproj/project.pbxproj +++ b/PowerHome.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ ACCC0D53203031410035F967 /* SignUpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D52203031410035F967 /* SignUpView.swift */; }; ACCC0D55203031A70035F967 /* LoginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D54203031A70035F967 /* LoginTests.swift */; }; ACCC0D57203031BB0035F967 /* SignUpTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D56203031BB0035F967 /* SignUpTests.swift */; }; + ACCC0D59203035F10035F967 /* BaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACCC0D58203035F10035F967 /* BaseView.swift */; }; ACFC97BD202FA648004A3FE3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACFC97BC202FA648004A3FE3 /* AppDelegate.swift */; }; ACFC97C4202FA648004A3FE3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ACFC97C3202FA648004A3FE3 /* Assets.xcassets */; }; ACFC97C7202FA648004A3FE3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ACFC97C5202FA648004A3FE3 /* LaunchScreen.storyboard */; }; @@ -44,6 +45,7 @@ ACCC0D52203031410035F967 /* SignUpView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpView.swift; sourceTree = ""; }; ACCC0D54203031A70035F967 /* LoginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginTests.swift; sourceTree = ""; }; ACCC0D56203031BB0035F967 /* SignUpTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpTests.swift; sourceTree = ""; }; + ACCC0D58203035F10035F967 /* BaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseView.swift; sourceTree = ""; }; ACFC97B9202FA648004A3FE3 /* PowerHome.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PowerHome.app; sourceTree = BUILT_PRODUCTS_DIR; }; ACFC97BC202FA648004A3FE3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; ACFC97C3202FA648004A3FE3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -151,6 +153,7 @@ children = ( ACFC97EE202FCF9F004A3FE3 /* LoginView.swift */, ACCC0D52203031410035F967 /* SignUpView.swift */, + ACCC0D58203035F10035F967 /* BaseView.swift */, ); name = Views; sourceTree = ""; @@ -312,6 +315,7 @@ ACFC97EB202FC889004A3FE3 /* LoginViewController.swift in Sources */, ACFC97BD202FA648004A3FE3 /* AppDelegate.swift in Sources */, ACCC0D4F20301DF10035F967 /* UISquareButton.swift in Sources */, + ACCC0D59203035F10035F967 /* BaseView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PowerHome/BaseView.swift b/PowerHome/BaseView.swift new file mode 100644 index 0000000..292ba76 --- /dev/null +++ b/PowerHome/BaseView.swift @@ -0,0 +1,34 @@ +// +// BaseView.swift +// PowerHome +// +// Created by Francisco Javier Chacon de Dios on 11/02/18. +// Copyright © 2018 Francisco Javier Chacon de Dios. All rights reserved. +// + +import UIKit + +class BaseView: UIView { + + override init(frame: CGRect) { + super.init(frame: frame) + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + +} + +extension BaseView: UITextFieldDelegate { + + @objc func dismissKeyboard(_ sender: Any) { + endEditing(true) + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + dismissKeyboard(Any.self) + return true + } + +} diff --git a/PowerHome/LoginView.swift b/PowerHome/LoginView.swift index f0ff813..b773247 100644 --- a/PowerHome/LoginView.swift +++ b/PowerHome/LoginView.swift @@ -9,7 +9,7 @@ import UIKit /// Login view to be used in -class LoginView: UIView { +class LoginView: BaseView { lazy var usernameLabel: UILabel = { let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) @@ -159,16 +159,3 @@ extension LoginView { addConstraints([loginButtonHeightConstraint, signUpButtonHeighConstraint]) } } - -extension LoginView: UITextFieldDelegate { - - @objc func dismissKeyboard(_ sender: Any) { - endEditing(true) - } - - func textFieldShouldReturn(_ textField: UITextField) -> Bool { - dismissKeyboard(Any.self) - return true - } - -} From b7a15b7c3a3f41b46a2eda4d3508f367a9b6bf06 Mon Sep 17 00:00:00 2001 From: Paco Chacon Date: Sun, 11 Feb 2018 02:40:28 -0600 Subject: [PATCH 5/6] Added fields and labels to sign up view --- PowerHome/SignUpView.swift | 98 +++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/PowerHome/SignUpView.swift b/PowerHome/SignUpView.swift index 028f5b7..0c48278 100644 --- a/PowerHome/SignUpView.swift +++ b/PowerHome/SignUpView.swift @@ -8,6 +8,102 @@ import UIKit -class SignUpView: UIView { +class SignUpView: BaseView { + + lazy var userNameLabel: UILabel = { + let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + label.text = "Name" + label.textColor = .darkGray + label.font = UIFont.systemFont(ofSize: 14) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + lazy var emailLabel: UILabel = { + let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + label.text = "Email" + label.textColor = .darkGray + label.font = UIFont.systemFont(ofSize: 14) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + lazy var passwordLabel: UILabel = { + let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + label.text = "Password" + label.textColor = .darkGray + label.font = UIFont.systemFont(ofSize: 14) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + lazy var passwordConfirmationLabel: UILabel = { + let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + label.text = "Password" + label.textColor = .darkGray + label.font = UIFont.systemFont(ofSize: 14) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + lazy var userNameTextField: UITextField = { + let textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + textField.placeholder = "First Name and Last Name" + textField.autocorrectionType = .no + textField.keyboardType = .default + textField.autocapitalizationType = .words + textField.borderStyle = .roundedRect + textField.translatesAutoresizingMaskIntoConstraints = false + textField.delegate = self + return textField + }() + + lazy var emailTextField: UITextField = { + let textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + textField.placeholder = "Email" + textField.autocorrectionType = .no + textField.keyboardType = .emailAddress + textField.autocapitalizationType = .none + textField.borderStyle = .roundedRect + textField.translatesAutoresizingMaskIntoConstraints = false + textField.delegate = self + return textField + }() + + lazy var passwordTextField: UITextField = { + let textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + textField.autocorrectionType = .no + textField.autocapitalizationType = .none + textField.borderStyle = .roundedRect + textField.isSecureTextEntry = true + textField.translatesAutoresizingMaskIntoConstraints = false + textField.delegate = self + return textField + }() + + lazy var passwordConfirmationTextField: UITextField = { + let textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) + textField.autocorrectionType = .no + textField.autocapitalizationType = .none + textField.borderStyle = .roundedRect + textField.isSecureTextEntry = true + textField.translatesAutoresizingMaskIntoConstraints = false + textField.delegate = self + return textField + }() + + lazy var signUpButton: UISquareButton = { + let button: UISquareButton = UISquareButton(buttonType: .system) + button.setTitle("Sign Up", for: .normal) + return button + }() + + override init(frame: CGRect) { + super.init(frame: frame) + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } } From 6f030a873763050935fe8857ddd4ba94d457f874 Mon Sep 17 00:00:00 2001 From: Paco Chacon Date: Sun, 11 Feb 2018 03:42:58 -0600 Subject: [PATCH 6/6] Show sign up view controller --- PowerHome/LoginView.swift | 1 + PowerHome/LoginViewController.swift | 8 +++++++- PowerHome/SignUpView.swift | 24 ++++++++++++++++++++++-- PowerHome/SignUpViewController.swift | 28 ++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/PowerHome/LoginView.swift b/PowerHome/LoginView.swift index b773247..3db9cd5 100644 --- a/PowerHome/LoginView.swift +++ b/PowerHome/LoginView.swift @@ -158,4 +158,5 @@ extension LoginView { addConstraints(signUpButtonEqualWidthsToUsernameLabelConstraints) addConstraints([loginButtonHeightConstraint, signUpButtonHeighConstraint]) } + } diff --git a/PowerHome/LoginViewController.swift b/PowerHome/LoginViewController.swift index f115d69..203ec87 100644 --- a/PowerHome/LoginViewController.swift +++ b/PowerHome/LoginViewController.swift @@ -16,8 +16,9 @@ class LoginViewController: UIViewController { super.viewDidLoad() view.backgroundColor = .white - view.addSubview(loginView) + + loginView.signUpButton.addTarget(self, action: #selector(showSignUp), for: .touchUpInside) // Do any additional setup after loading the view. } @@ -31,4 +32,9 @@ class LoginViewController: UIViewController { view.addConstraints(loginViewHorizontalConstraints) } + @objc func showSignUp() { + let navigationController: UINavigationController = UINavigationController(rootViewController: SignUpViewController()) + present(navigationController, animated: true, completion: nil) + } + } diff --git a/PowerHome/SignUpView.swift b/PowerHome/SignUpView.swift index 0c48278..88bc586 100644 --- a/PowerHome/SignUpView.swift +++ b/PowerHome/SignUpView.swift @@ -10,7 +10,7 @@ import UIKit class SignUpView: BaseView { - lazy var userNameLabel: UILabel = { + lazy var nameLabel: UILabel = { let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) label.text = "Name" label.textColor = .darkGray @@ -46,7 +46,7 @@ class SignUpView: BaseView { return label }() - lazy var userNameTextField: UITextField = { + lazy var nameTextField: UITextField = { let textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) textField.placeholder = "First Name and Last Name" textField.autocorrectionType = .no @@ -94,12 +94,17 @@ class SignUpView: BaseView { lazy var signUpButton: UISquareButton = { let button: UISquareButton = UISquareButton(buttonType: .system) + button.translatesAutoresizingMaskIntoConstraints = false button.setTitle("Sign Up", for: .normal) return button }() override init(frame: CGRect) { super.init(frame: frame) + + backgroundColor = .white + translatesAutoresizingMaskIntoConstraints = false + addSubview(nameLabel) } required init?(coder aDecoder: NSCoder) { @@ -107,3 +112,18 @@ class SignUpView: BaseView { } } + +// MARK: - AutoLayout +extension SignUpView { + + override func updateConstraints() { + super.updateConstraints() + + let nameLabelHorizontalConstraints: [NSLayoutConstraint] = NSLayoutConstraint.constraints(withVisualFormat: "H:|-15-[nameLabel]-15-|", options: .alignAllBottom, metrics: nil, views: ["nameLabel": nameLabel]) + let verticalSpacingConstraints: [NSLayoutConstraint] = NSLayoutConstraint.constraints(withVisualFormat: "V:|-15-[nameLabel]", options: .alignAllLeading, metrics: nil, views: ["nameLabel": nameLabel]) + + addConstraints(nameLabelHorizontalConstraints) + addConstraints(verticalSpacingConstraints) + } + +} diff --git a/PowerHome/SignUpViewController.swift b/PowerHome/SignUpViewController.swift index 060453a..f6f0fcb 100644 --- a/PowerHome/SignUpViewController.swift +++ b/PowerHome/SignUpViewController.swift @@ -10,10 +10,38 @@ import UIKit class SignUpViewController: UIViewController { + let signUpView: SignUpView = SignUpView() + lazy var cancelBarButton: UIBarButtonItem = { + let cancelButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(dismiss(_:))) + return cancelButton + }() + override func viewDidLoad() { super.viewDidLoad() + viewRespectsSystemMinimumLayoutMargins = false + navigationItem.leftBarButtonItem = cancelBarButton + navigationItem.title = "Sign Up" + view.addSubview(signUpView) // Do any additional setup after loading the view. } + override func viewWillLayoutSubviews() { + super.viewWillLayoutSubviews() + + let signUpViewHorizontalConstraints: [NSLayoutConstraint] = NSLayoutConstraint.constraints(withVisualFormat: "H:|-[view]-|", options: .alignAllCenterX, metrics: nil, views: ["view": signUpView]) + let signUpVerticalConstraints: [NSLayoutConstraint] = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[view]-|", options: .alignAllCenterY, metrics: nil, views: ["view": signUpView]) + + view.addConstraints(signUpVerticalConstraints) + view.addConstraints(signUpViewHorizontalConstraints) + } + +} + +extension SignUpViewController { + + @objc func dismiss(_ sender: UIBarButtonItem) { + dismiss(animated: true, completion: nil) + } + }