aboutsummaryrefslogtreecommitdiff
path: root/foray
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-03-19 13:50:15 +1100
committerNicholas Tay <nick@windblume.net>2022-03-19 13:50:15 +1100
commit61452377e01956205293883d4e1222c1ed2651cf (patch)
tree9cc7bcad5abce098e3651eff8b8e09192b7a3865 /foray
parentf61362258fc9906eec44e8aa3095757f1cb2df45 (diff)
downloadforayios-61452377e01956205293883d4e1222c1ed2651cf.tar.gz
forayios-61452377e01956205293883d4e1222c1ed2651cf.tar.bz2
forayios-61452377e01956205293883d4e1222c1ed2651cf.zip
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.
Diffstat (limited to '')
-rw-r--r--foray.xcodeproj/project.pbxproj4
-rw-r--r--foray/ForayDetailViewController.swift76
-rw-r--r--foray/ForayNewDetailView.swift86
3 files changed, 71 insertions, 95 deletions
diff --git a/foray.xcodeproj/project.pbxproj b/foray.xcodeproj/project.pbxproj
index 9593082..6c2e2c4 100644
--- a/foray.xcodeproj/project.pbxproj
+++ b/foray.xcodeproj/project.pbxproj
@@ -13,7 +13,6 @@
C04B45B827DEF2ED001451A3 /* ForayTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */; };
C04EDE4227E428AB00D83005 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = C04EDE4127E428AB00D83005 /* SnapKit */; };
C04EDE4427E4298D00D83005 /* ForayNewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04EDE4327E4298D00D83005 /* ForayNewTableViewCell.swift */; };
- C04EDE4627E45CCA00D83005 /* ForayNewDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04EDE4527E45CCA00D83005 /* ForayNewDetailView.swift */; };
C0FEAF5F27E14C52000A7648 /* ForayDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */; };
/* End PBXBuildFile section */
@@ -25,7 +24,6 @@
C04B45B127DEF118001451A3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForayTableViewController.swift; sourceTree = "<group>"; };
C04EDE4327E4298D00D83005 /* ForayNewTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForayNewTableViewCell.swift; sourceTree = "<group>"; };
- C04EDE4527E45CCA00D83005 /* ForayNewDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForayNewDetailView.swift; sourceTree = "<group>"; };
C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForayDetailViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -62,7 +60,6 @@
children = (
C04B45A327DEF117001451A3 /* AppDelegate.swift */,
C04B45A527DEF117001451A3 /* SceneDelegate.swift */,
- C04EDE4527E45CCA00D83005 /* ForayNewDetailView.swift */,
C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */,
C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */,
C04EDE4327E4298D00D83005 /* ForayNewTableViewCell.swift */,
@@ -149,7 +146,6 @@
files = (
C04B45B827DEF2ED001451A3 /* ForayTableViewController.swift in Sources */,
C0FEAF5F27E14C52000A7648 /* ForayDetailViewController.swift in Sources */,
- C04EDE4627E45CCA00D83005 /* ForayNewDetailView.swift in Sources */,
C04EDE4427E4298D00D83005 /* ForayNewTableViewCell.swift in Sources */,
C04B45A427DEF117001451A3 /* AppDelegate.swift in Sources */,
C04B45A627DEF117001451A3 /* SceneDelegate.swift in Sources */,
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)
- }
-}