-
Notifications
You must be signed in to change notification settings - Fork 43
Criando a ContactListView e a ContactCellView #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
24bedee
c755d27
e65aa75
212bb20
55140f9
2ea136c
889b10f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "filename" : "img.png", | ||
| "idiom" : "universal", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "filename" : "img2.png", | ||
| "idiom" : "universal", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "filename" : "img3.png", | ||
| "idiom" : "universal", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "filename" : "img4.png", | ||
| "idiom" : "universal", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "filename" : "img5.png", | ||
| "idiom" : "universal", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "filename" : "img6.png", | ||
| "idiom" : "universal", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "images" : [ | ||
| { | ||
| "filename" : "img7.png", | ||
| "idiom" : "universal", | ||
| "scale" : "1x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "2x" | ||
| }, | ||
| { | ||
| "idiom" : "universal", | ||
| "scale" : "3x" | ||
| } | ||
| ], | ||
| "info" : { | ||
| "author" : "xcode", | ||
| "version" : 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,9 @@ import UIKit | |
|
|
||
| class ContactCellView { | ||
|
||
|
|
||
| private lazy var contactListView: ContactListView = { | ||
| let contactListView = ContactListView() | ||
| return contactListView | ||
| }() | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // | ||
| // ContactListModel.swift | ||
| // FinanceApp | ||
| // | ||
| // Created by Kleiton Mendes on 09/12/22. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct ContactListModel { | ||
| let name: String | ||
| let phone: String | ||
| let image: String? | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
||
| let contactList: [ContactListModel] = [ | ||
| ContactListModel(name: "Ronald Robertson", phone: "+55 (11) 99999-9999", image: "img"), | ||
| ContactListModel(name: "Johnny Watson", phone: "+55 (11) 99999-9999", image: "img2"), | ||
| ContactListModel(name: "Annette Cooper", phone: "+55 (11) 99999-9999", image: "img3"), | ||
| ContactListModel(name: "Arthur Bell", phone: "+55 (11) 99999-9999", image: "img4"), | ||
| ContactListModel(name: "Jane Warren", phone: "+55 (11) 99999-9999", image: "img5"), | ||
| ContactListModel(name: "JMorris Henry", phone: "+55 (11) 99999-9999", image: "img6"), | ||
| ContactListModel(name: "Irma Flores", phone: "+55 (11) 99999-9999", image: "img7"), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,5 +8,82 @@ | |
| import UIKit | ||
|
|
||
| class ContactListView: UIView { | ||
|
|
||
| // private lazy var titleLabel: UILabel = { | ||
| // let label = UILabel() | ||
| // label.translatesAutoresizingMaskIntoConstraints = false | ||
| // label.numberOfLines = 0 | ||
|
||
| // label.textColor = .black | ||
| // label.font = .boldSystemFont(ofSize: 20) | ||
| // label.textAlignment = .left | ||
| // label.text = "Contact List" | ||
| // label.backgroundColor = .gray | ||
| // return label | ||
| // }() | ||
|
|
||
| private let imagePerson: UIImageView = { | ||
| let image = UIImageView(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) | ||
| image.translatesAutoresizingMaskIntoConstraints = false | ||
| image.layer.cornerRadius = 10 | ||
| image.clipsToBounds = true | ||
| image.layer.masksToBounds = true | ||
| image.backgroundColor = .gray | ||
| image.contentMode = .scaleToFill | ||
| return image | ||
| }() | ||
|
|
||
| private lazy var nameLabel: UILabel = { | ||
| let label = UILabel() | ||
| label.translatesAutoresizingMaskIntoConstraints = false | ||
| label.numberOfLines = 0 | ||
| label.textColor = .black | ||
| label.font = .boldSystemFont(ofSize: 15) | ||
| label.textAlignment = .left | ||
| label.text = "Ronald Robertson" | ||
| return label | ||
| }() | ||
|
|
||
| private lazy var phoneLabel: UILabel = { | ||
| let label = UILabel() | ||
| label.translatesAutoresizingMaskIntoConstraints = false | ||
| label.numberOfLines = 0 | ||
| label.textColor = .gray | ||
| label.font = .boldSystemFont(ofSize: 13) | ||
| label.textAlignment = .left | ||
| label.text = "+55 (11)99999-9999" | ||
| return label | ||
| }() | ||
|
|
||
| private lazy var stackView: UIStackView = { | ||
| let stackView = UIStackView() | ||
| stackView.translatesAutoresizingMaskIntoConstraints = false | ||
| return stackView | ||
| }() | ||
|
|
||
| private func confighierarchy() { | ||
| // addSubview(titleLabel) | ||
|
||
| addSubview(imagePerson) | ||
| stackView.addArrangedSubview(nameLabel) | ||
| stackView.addArrangedSubview(phoneLabel) | ||
| } | ||
|
|
||
|
|
||
| private func configConstraints() { | ||
| NSLayoutConstraint.activate([ | ||
|
|
||
| // titleLabel.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor, constant: 32.0), | ||
| // titleLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor), | ||
|
||
| // titleLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor), | ||
|
|
||
| imagePerson.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 10.0), | ||
| imagePerson.trailingAnchor.constraint(equalTo: stackView.trailingAnchor, constant: -10), | ||
|
|
||
|
|
||
| stackView.topAnchor.constraint(equalTo: topAnchor, constant: 16.0), | ||
| stackView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -16.0), | ||
| stackView.leadingAnchor.constraint(equalTo: imagePerson.leadingAnchor, constant: 24.0), | ||
| stackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -24.0), | ||
| ]) | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,5 +11,68 @@ class ContactListViewController: UIViewController { | |
|
|
||
| override func loadView() { | ||
| self.view = ContactListView() | ||
|
|
||
| confighierarchy() | ||
| configConstraints() | ||
| } | ||
|
|
||
|
|
||
| private lazy var contactCellView: ContactCellView = { | ||
|
||
| let contactCellView = ContactCellView() | ||
| return contactCellView | ||
| }() | ||
|
|
||
| private lazy var titleLabel: UILabel = { | ||
| let label = UILabel() | ||
| label.translatesAutoresizingMaskIntoConstraints = false | ||
| label.numberOfLines = 0 | ||
| label.textColor = .black | ||
| label.font = .boldSystemFont(ofSize: 20) | ||
| label.textAlignment = .left | ||
| label.text = "Contact List" | ||
| label.backgroundColor = .gray | ||
| return label | ||
| }() | ||
|
|
||
| private lazy var contactTableView: UITableView = { | ||
| let tableView = UITableView(frame: .zero, style: .plain) | ||
| tableView.translatesAutoresizingMaskIntoConstraints = false | ||
| tableView.delegate = self | ||
| tableView.dataSource = self | ||
| tableView.backgroundColor = .clear | ||
| tableView.register(ContactCellView.self, forCellReuseIdentifier: "cell") | ||
| tableView.separatorStyle = .none | ||
| return tableView | ||
| }() | ||
|
|
||
|
|
||
| private func confighierarchy() { | ||
| view.addSubview(titleLabel) | ||
| view.addSubview(contactTableView) | ||
| } | ||
|
|
||
|
|
||
| private func configConstraints() { | ||
| NSLayoutConstraint.activate([ | ||
|
|
||
| titleLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), | ||
| titleLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
|
|
||
| contactTableView.topAnchor.constraint(equalTo: titleLabel.topAnchor), | ||
| contactTableView.centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
| contactTableView.centerYAnchor.constraint(equalTo: view.centerYAnchor), | ||
| contactTableView.bottomAnchor.constraint(equalTo: view.bottomAnchor) | ||
| ]) | ||
| } | ||
| } | ||
|
|
||
| extension ContactListViewController: UITableViewDelegate, UITableViewDataSource { | ||
| func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
| let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell | ||
| cell.textLabel?.text = contactList[indexPath.row].name | ||
| return cell | ||
| } | ||
| func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
| return contactList.count | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[QUESTION]
Opa @kleitonm, não deveriamos manter o HomeViewController ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Foi mal, eu esqueci que não era pra subir, eu tinha substituído para testar a minha tela