From 61452377e01956205293883d4e1222c1ed2651cf Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Sat, 19 Mar 2022 13:50:15 +1100 Subject: Merge ForayNewDetailView into the VC itself Not sure if this is the right move, but it felt extraneous to have a whole UIView to itself for now. Instead just have it right inside the VC. Probably a step in the wrong direction though, but will need to review. --- foray/ForayDetailViewController.swift | 76 +++++++++++++++++++++++++++++-- foray/ForayNewDetailView.swift | 86 ----------------------------------- 2 files changed, 71 insertions(+), 91 deletions(-) delete mode 100644 foray/ForayNewDetailView.swift (limited to 'foray') diff --git a/foray/ForayDetailViewController.swift b/foray/ForayDetailViewController.swift index 92abef1..8d0b9ec 100644 --- a/foray/ForayDetailViewController.swift +++ b/foray/ForayDetailViewController.swift @@ -9,22 +9,88 @@ import UIKit class ForayDetailViewController: UIViewController { - let detailView: ForayNewDetailView = ForayNewDetailView(frame: CGRect.zero) + let container: UIView = UIView() + + let nameLabel: UILabel = { + let l = UILabel() + l.font = UIFont.preferredFont(forTextStyle: .largeTitle) + l.adjustsFontForContentSizeCategory = true + l.numberOfLines = 3 + l.textAlignment = .center + return l + }() + + let itemImageView: UIImageView = { + let iv = UIImageView() + iv.contentMode = .scaleAspectFit + return iv + }() + + let descLabel: UILabel = { + let l = UILabel() + l.font = UIFont.preferredFont(forTextStyle: .body) + l.adjustsFontForContentSizeCategory = true + l.numberOfLines = 10 + return l + }() override func viewDidLoad() { super.viewDidLoad() - self.title = "Details" + self.title = "Details" self.view.backgroundColor = .systemBackground - self.view.addSubview(detailView) - detailView.snp.makeConstraints { (make) in + initialiseViews() + } + + private func initialiseViews() { + self.view.addSubview(container) + + container.addSubview(nameLabel) + container.addSubview(itemImageView) + container.addSubview(descLabel) + + setupConstraints() + } + + private func setupConstraints() { + container.snp.makeConstraints { (make) in make.edges.equalTo(self.view.snp.margins) } + + nameLabel.snp.makeConstraints { (make) in + make.top.equalToSuperview().inset(8) + make.leading.trailing.equalToSuperview().inset(8) + } + itemImageView.snp.makeConstraints { (make) in + make.top.equalTo(nameLabel.snp.bottom).offset(32) + make.leading.trailing.equalToSuperview() + make.height.equalTo(150) + } + descLabel.snp.makeConstraints { (make) in + make.top.equalTo(itemImageView.snp.bottom).offset(32) + make.leading.trailing.equalToSuperview() + } } public func setSelectedItem(selectedItem: PenguinItem) { - detailView.setSelectedItem(selectedItem: selectedItem) + nameLabel.text = selectedItem.name + itemImageView.image = UIImage(named: selectedItem.id) + + descLabel.text = "Type: " + switch selectedItem.type { + case .item: + descLabel.text! += "Item" + case .quest: + descLabel.text! += "Quest" + itemImageView.image = UIImage(named: "spy") + } + + descLabel.text! += "\nID: " + selectedItem.id + + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd" + descLabel.text! += "\nReleased: " + dateFormatter.string(from: selectedItem.releaseDate) } } diff --git a/foray/ForayNewDetailView.swift b/foray/ForayNewDetailView.swift deleted file mode 100644 index e8e2262..0000000 --- a/foray/ForayNewDetailView.swift +++ /dev/null @@ -1,86 +0,0 @@ -// -// ForayNewDetailView.swift -// foray -// -// Created by Nicholas Tay on 18/3/2022. -// - -import UIKit - -class ForayNewDetailView: UIView { - - let nameLabel: UILabel = { - let l = UILabel() - l.font = UIFont.preferredFont(forTextStyle: .largeTitle) - l.adjustsFontForContentSizeCategory = true - l.numberOfLines = 3 - l.textAlignment = .center - return l - }() - - let itemImageView: UIImageView = { - let iv = UIImageView() - iv.contentMode = .scaleAspectFit - return iv - }() - - let descLabel: UILabel = { - let l = UILabel() - l.font = UIFont.preferredFont(forTextStyle: .body) - l.adjustsFontForContentSizeCategory = true - l.numberOfLines = 10 - return l - }() - - override init(frame: CGRect) { - super.init(frame: frame) - initialiseViews() - } - - required init?(coder: NSCoder) { - fatalError("unreachable") - } - - private func initialiseViews() { - addSubview(nameLabel) - addSubview(itemImageView) - addSubview(descLabel) - setupConstraints() - } - - private func setupConstraints() { - nameLabel.snp.makeConstraints { (make) in - make.top.equalToSuperview().inset(8) - make.leading.trailing.equalToSuperview().inset(8) - } - itemImageView.snp.makeConstraints { (make) in - make.top.equalTo(nameLabel.snp.bottom).offset(32) - make.leading.trailing.equalToSuperview() - make.height.equalTo(150) - } - descLabel.snp.makeConstraints { (make) in - make.top.equalTo(itemImageView.snp.bottom).offset(32) - make.leading.trailing.equalToSuperview() - } - } - - public func setSelectedItem(selectedItem: PenguinItem) { - nameLabel.text = selectedItem.name - itemImageView.image = UIImage(named: selectedItem.id) - - descLabel.text = "Type: " - switch selectedItem.type { - case .item: - descLabel.text! += "Item" - case .quest: - descLabel.text! += "Quest" - itemImageView.image = UIImage(named: "spy") - } - - descLabel.text! += "\nID: " + selectedItem.id - - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd" - descLabel.text! += "\nReleased: " + dateFormatter.string(from: selectedItem.releaseDate) - } -} -- cgit