aboutsummaryrefslogtreecommitdiff
path: root/foray
diff options
context:
space:
mode:
Diffstat (limited to 'foray')
-rw-r--r--foray/ForayDetailViewController.swift76
-rw-r--r--foray/ForayNewDetailView.swift86
2 files changed, 71 insertions, 91 deletions
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)
- }
-}