From ae4ad4837ebc150237d02889cecf2683aec7428a Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Sat, 11 Feb 2017 20:45:56 +0800 Subject: [PATCH] update UI of add password page --- pass.xcodeproj/project.pbxproj | 8 +++ .../AddPasswordTableViewController.swift | 30 ++++++++--- pass/Views/TextFieldTableViewCell.swift | 9 ---- pass/Views/TextFieldTableViewCell.xib | 25 ++++----- pass/Views/TextViewTableViewCell.swift | 9 ---- pass/Views/TextViewTableViewCell.xib | 24 +++------ pass/Views/TitleTextFieldTableViewCell.swift | 32 ++++++++++++ pass/Views/TitleTextFieldTableViewCell.xib | 52 +++++++++++++++++++ 8 files changed, 131 insertions(+), 58 deletions(-) create mode 100644 pass/Views/TitleTextFieldTableViewCell.swift create mode 100644 pass/Views/TitleTextFieldTableViewCell.xib diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index b60ae6d..71595f6 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -50,6 +50,8 @@ DCDDEAB01E4639F300F68193 /* LabelTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DCDDEAAF1E4639F300F68193 /* LabelTableViewCell.xib */; }; DCDDEAB31E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCDDEAB11E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift */; }; DCDDEAB41E4896BF00F68193 /* PasswordDetailTitleTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DCDDEAB21E4896BF00F68193 /* PasswordDetailTitleTableViewCell.xib */; }; + DCFB779A1E4F3BCF008DE471 /* TitleTextFieldTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFB77981E4F3BCF008DE471 /* TitleTextFieldTableViewCell.swift */; }; + DCFB779B1E4F3BCF008DE471 /* TitleTextFieldTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = DCFB77991E4F3BCF008DE471 /* TitleTextFieldTableViewCell.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -101,6 +103,8 @@ DCDDEAAF1E4639F300F68193 /* LabelTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = LabelTableViewCell.xib; path = ../LabelTableViewCell.xib; sourceTree = ""; }; DCDDEAB11E4896BF00F68193 /* PasswordDetailTitleTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordDetailTitleTableViewCell.swift; sourceTree = ""; }; DCDDEAB21E4896BF00F68193 /* PasswordDetailTitleTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = PasswordDetailTitleTableViewCell.xib; path = ../PasswordDetailTitleTableViewCell.xib; sourceTree = ""; }; + DCFB77981E4F3BCF008DE471 /* TitleTextFieldTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TitleTextFieldTableViewCell.swift; sourceTree = ""; }; + DCFB77991E4F3BCF008DE471 /* TitleTextFieldTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TitleTextFieldTableViewCell.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -178,6 +182,8 @@ DC19400F1E4B3A9E0077E0A3 /* Views */ = { isa = PBXGroup; children = ( + DCFB77981E4F3BCF008DE471 /* TitleTextFieldTableViewCell.swift */, + DCFB77991E4F3BCF008DE471 /* TitleTextFieldTableViewCell.xib */, DC4914941E434301007FF592 /* LabelTableViewCell.swift */, DCDDEAAF1E4639F300F68193 /* LabelTableViewCell.xib */, DC037CB91E4DD47B00609409 /* TextFieldTableViewCell.swift */, @@ -309,6 +315,7 @@ DCDDEAB41E4896BF00F68193 /* PasswordDetailTitleTableViewCell.xib in Resources */, DCDDEAB01E4639F300F68193 /* LabelTableViewCell.xib in Resources */, DC917BDC1E2E8231000FDF54 /* Main.storyboard in Resources */, + DCFB779B1E4F3BCF008DE471 /* TitleTextFieldTableViewCell.xib in Resources */, DC037CC01E4ED4E100609409 /* TextViewTableViewCell.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -411,6 +418,7 @@ DC037CB81E4DD1A500609409 /* AddPasswordTableViewController.swift in Sources */, DC1940001E49E1A60077E0A3 /* PasscodeLockConfiguration.swift in Sources */, DC917BD71E2E8231000FDF54 /* AppDelegate.swift in Sources */, + DCFB779A1E4F3BCF008DE471 /* TitleTextFieldTableViewCell.swift in Sources */, DC037CBB1E4DD47B00609409 /* TextFieldTableViewCell.swift in Sources */, DC193FFE1E49E0760077E0A3 /* PasscodeLockRepository.swift in Sources */, DCA049981E33586A00522E8F /* DefaultsKeys.swift in Sources */, diff --git a/pass/Controllers/AddPasswordTableViewController.swift b/pass/Controllers/AddPasswordTableViewController.swift index 2c1e0b8..25f249a 100644 --- a/pass/Controllers/AddPasswordTableViewController.swift +++ b/pass/Controllers/AddPasswordTableViewController.swift @@ -18,27 +18,36 @@ class AddPasswordTableViewController: UITableViewController { tableView.register(UINib(nibName: "TextViewTableViewCell", bundle: nil), forCellReuseIdentifier: "textViewCell") tableView.rowHeight = UITableViewAutomaticDimension - tableView.estimatedRowHeight = 64 + tableView.estimatedRowHeight = 48 tableView.allowsSelection = false } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 1 + } + + override func numberOfSections(in tableView: UITableView) -> Int { return tableTitles.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - if tableTitles[indexPath.row] == "additions" { + if tableTitles[indexPath.section] == "additions" { let cell = tableView.dequeueReusableCell(withIdentifier: "textViewCell", for: indexPath) as! TextViewTableViewCell - cell.titleLabel.text = tableTitles[indexPath.row] cell.contentTextView.text = "" return cell } else { let cell = tableView.dequeueReusableCell(withIdentifier: "textFieldCell", for: indexPath) as! TextFieldTableViewCell - cell.titleLabel.text = tableTitles[indexPath.row] return cell } } + override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + print(section) + let headerView = UITableViewHeaderFooterView() + headerView.textLabel?.text = tableTitles[section].uppercased() + return headerView + } + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "saveAddPasswordSegue" { let nameCell = getCellForName(name: "name")! as! TextFieldTableViewCell @@ -47,13 +56,20 @@ class AddPasswordTableViewController: UITableViewController { password = Password(name: nameCell.contentTextField.text!, plainText: "\(passwordCell.contentTextField.text!)\n\(additionsCell.contentTextView.text!)") } } + override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + return 44 + } - func getCellAt(row: Int) -> UITableViewCell? { - return tableView.cellForRow(at: IndexPath(row: row, section: 0)) + override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + return 0.1 + } + + func getCellAt(section: Int) -> UITableViewCell? { + return tableView.cellForRow(at: IndexPath(row: 0, section: section)) } func getCellForName(name: String) -> UITableViewCell? { let index = tableTitles.index(of: name)! - return getCellAt(row: Int(index)) + return getCellAt(section: Int(index)) } } diff --git a/pass/Views/TextFieldTableViewCell.swift b/pass/Views/TextFieldTableViewCell.swift index 2267c67..c134740 100644 --- a/pass/Views/TextFieldTableViewCell.swift +++ b/pass/Views/TextFieldTableViewCell.swift @@ -10,21 +10,12 @@ import UIKit class TextFieldTableViewCell: UITableViewCell { - @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var contentTextField: UITextField! override func awakeFromNib() { super.awakeFromNib() - // Initialization code - titleLabel.isUserInteractionEnabled = true - let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tap(_:))) - titleLabel.addGestureRecognizer(tapGestureRecognizer) } - func tap(_ sender: Any?) { - contentTextField.becomeFirstResponder() - } - override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } diff --git a/pass/Views/TextFieldTableViewCell.xib b/pass/Views/TextFieldTableViewCell.xib index 480b969..000fbd6 100644 --- a/pass/Views/TextFieldTableViewCell.xib +++ b/pass/Views/TextFieldTableViewCell.xib @@ -16,35 +16,28 @@ - + - - + + + + - - - - - - - + + + + - diff --git a/pass/Views/TextViewTableViewCell.swift b/pass/Views/TextViewTableViewCell.swift index 88914d2..899bf99 100644 --- a/pass/Views/TextViewTableViewCell.swift +++ b/pass/Views/TextViewTableViewCell.swift @@ -11,18 +11,9 @@ import UIKit class TextViewTableViewCell: UITableViewCell { @IBOutlet weak var contentTextView: UITextView! - @IBOutlet weak var titleLabel: UILabel! override func awakeFromNib() { super.awakeFromNib() - titleLabel.isUserInteractionEnabled = true - let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tap(_:))) - titleLabel.addGestureRecognizer(tapGestureRecognizer) } - - func tap(_ sender: Any?) { - contentTextView.becomeFirstResponder() - } - override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } diff --git a/pass/Views/TextViewTableViewCell.xib b/pass/Views/TextViewTableViewCell.xib index b06cf8a..1089f3c 100644 --- a/pass/Views/TextViewTableViewCell.xib +++ b/pass/Views/TextViewTableViewCell.xib @@ -16,39 +16,29 @@ - + - - + - + - Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. - - - + + - - - + - diff --git a/pass/Views/TitleTextFieldTableViewCell.swift b/pass/Views/TitleTextFieldTableViewCell.swift new file mode 100644 index 0000000..b17a692 --- /dev/null +++ b/pass/Views/TitleTextFieldTableViewCell.swift @@ -0,0 +1,32 @@ +// +// TextFieldTableViewCell.swift +// pass +// +// Created by Mingshen Sun on 10/2/2017. +// Copyright © 2017 Bob Sun. All rights reserved. +// + +import UIKit + +class TitleTextFieldTableViewCell: UITableViewCell { + + @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var contentTextField: UITextField! + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + titleLabel.isUserInteractionEnabled = true + let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tap(_:))) + titleLabel.addGestureRecognizer(tapGestureRecognizer) + } + + func tap(_ sender: Any?) { + contentTextField.becomeFirstResponder() + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + } + +} diff --git a/pass/Views/TitleTextFieldTableViewCell.xib b/pass/Views/TitleTextFieldTableViewCell.xib new file mode 100644 index 0000000..37cdf0d --- /dev/null +++ b/pass/Views/TitleTextFieldTableViewCell.xib @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +