Skip to content

Implementando a tela AccountSummaryView #80

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,159 @@

import UIKit

class AccountSummaryView {
class AccountSummaryView: UIView {
// MARK: UI Components
lazy var balanceLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = "$15,459.27"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Injetar

label.numberOfLines = 0
label.font = .boldSystemFont(ofSize: 34)
label.textAlignment = .left
return label
}()

lazy var economyLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = "Savings"
label.numberOfLines = 0
label.font = .systemFont(ofSize: 17)
label.textAlignment = .left
return label
}()

lazy var economyValueLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = "$1000"
label.numberOfLines = 0
label.font = .boldSystemFont(ofSize: 34)
label.textColor = .gray
label.textAlignment = .right
return label
}()

lazy var spendingLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = "Spendings"
label.numberOfLines = 0
label.font = .systemFont(ofSize: 17)
label.textAlignment = .left
return label
}()

lazy var spendingValueLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = "500"
label.numberOfLines = 0
label.font = .boldSystemFont(ofSize: 34)
label.textColor = .gray
label.textAlignment = .right
return label
}()

lazy var greenView: UIView = {
let view = UIView()
view.backgroundColor = .green
view.layer.cornerRadius = 5
return view
}()

lazy var redView: UIView = {
let view = UIView()
view.backgroundColor = .red
view.layer.cornerRadius = 5
return view
}()

lazy var firstStackView: UIStackView = {
let stack = UIStackView()
stack.axis = .vertical
stack.translatesAutoresizingMaskIntoConstraints = false
return stack
}()

lazy var secondStackView: UIStackView = {
let stack = UIStackView()
stack.axis = .vertical
stack.translatesAutoresizingMaskIntoConstraints = false
return stack
}()

lazy var thirdStackView: UIStackView = {
let stack = UIStackView()
stack.axis = .vertical
stack.translatesAutoresizingMaskIntoConstraints = false
return stack
}()
// MARK: init
init() {
super.init(frame: .zero)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension AccountSummaryView {

// MARK: - Private Methods
private func setupViews() {
confighierarchy()
configConstraints()
}
private func confighierarchy() {

addSubview(greenView)

addSubview(redView)

addSubview(firstStackView)
firstStackView.addArrangedSubview(balanceLabel)

addSubview(secondStackView)
secondStackView.addArrangedSubview(economyLabel)
secondStackView.addArrangedSubview(economyValueLabel)

addSubview(thirdStackView)
thirdStackView.addArrangedSubview(spendingLabel)
thirdStackView.addArrangedSubview(spendingValueLabel)
}

private func configConstraints() {
NSLayoutConstraint.activate([

greenView.topAnchor.constraint(equalTo: self.topAnchor, constant: 16),
greenView.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -16),
greenView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
greenView.heightAnchor.constraint(equalToConstant: 10.0),
greenView.widthAnchor.constraint(equalToConstant: 10.0),

redView.topAnchor.constraint(equalTo: self.topAnchor, constant: 16),
redView.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -16),
redView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
redView.heightAnchor.constraint(equalToConstant: 10.0),
redView.widthAnchor.constraint(equalToConstant: 10.0),

firstStackView.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor),
firstStackView.centerYAnchor.constraint(equalTo: self.centerYAnchor),
firstStackView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
firstStackView.trailingAnchor.constraint(equalTo: self.trailingAnchor),

secondStackView.topAnchor.constraint(equalTo: self.firstStackView.bottomAnchor, constant: 10),
secondStackView.centerYAnchor.constraint(equalTo: self.centerYAnchor),
secondStackView.leadingAnchor.constraint(equalTo: greenView.trailingAnchor, constant: 20.0),
secondStackView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20.0),


thirdStackView.topAnchor.constraint(equalTo: self.secondStackView.bottomAnchor, constant: 10),
thirdStackView.centerYAnchor.constraint(equalTo: self.centerYAnchor),
thirdStackView.leadingAnchor.constraint(equalTo: redView.trailingAnchor, constant: 20.0),
thirdStackView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -20.0),
])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ class HomeViewController: UIViewController {
private let service = FinanceService()

private let homeView: HomeView = {

let homeView = HomeView()
return homeView
}()
//
let accountView: AccountSummaryView = {
let accountView = AccountSummaryView()
return accountView
}()

override func viewDidLoad() {

Expand All @@ -36,8 +40,38 @@ class HomeViewController: UIViewController {
}
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

override func loadView() {
self.view = homeView
// override func loadView() {
// self.view = homeView
// }
}

extension HomeViewController {
private func setupViews() {
confighierarchy()
configConstraints()
}

private func confighierarchy() {
view.addSubview(accountView)
view.addSubview(homeView)
}

private func configConstraints() {
NSLayoutConstraint.activate([

accountView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
accountView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
accountView.trailingAnchor.constraint(equalTo: view.trailingAnchor),

homeView.topAnchor.constraint(equalTo: accountView.bottomAnchor),
accountView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
accountView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
}

}