aboutsummaryrefslogtreecommitdiff
path: root/foray
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-03-19 13:08:40 +1100
committerNicholas Tay <nick@windblume.net>2022-03-19 13:08:40 +1100
commitf19a09c0e91668a48c1958fc9a4fa07f963c4142 (patch)
tree0bce6b10129afe7c75239e0f4eea0e2521d838a3 /foray
parent34531178eb042f5bc1439bce5b6dde543fbb96ab (diff)
downloadforayios-f19a09c0e91668a48c1958fc9a4fa07f963c4142.tar.gz
forayios-f19a09c0e91668a48c1958fc9a4fa07f963c4142.tar.bz2
forayios-f19a09c0e91668a48c1958fc9a4fa07f963c4142.zip
Detail view is now programatically created
Using SnapKit and some experimentation around the VC. Next step is to change segue and then maybe get rid of storyboard all together.
Diffstat (limited to '')
-rw-r--r--foray.xcodeproj/project.pbxproj4
-rw-r--r--foray/Base.lproj/Main.storyboard51
-rw-r--r--foray/ForayDetailViewController.swift28
-rw-r--r--foray/ForayNewDetailView.swift85
4 files changed, 98 insertions, 70 deletions
diff --git a/foray.xcodeproj/project.pbxproj b/foray.xcodeproj/project.pbxproj
index 50615ca..3423ae5 100644
--- a/foray.xcodeproj/project.pbxproj
+++ b/foray.xcodeproj/project.pbxproj
@@ -15,6 +15,7 @@
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 */
@@ -28,6 +29,7 @@
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 */
@@ -65,6 +67,7 @@
C04B45A327DEF117001451A3 /* AppDelegate.swift */,
C04B45A527DEF117001451A3 /* SceneDelegate.swift */,
C04B45A927DEF117001451A3 /* Main.storyboard */,
+ C04EDE4527E45CCA00D83005 /* ForayNewDetailView.swift */,
C0FEAF5E27E14C52000A7648 /* ForayDetailViewController.swift */,
C04B45B727DEF2ED001451A3 /* ForayTableViewController.swift */,
C04EDE4327E4298D00D83005 /* ForayNewTableViewCell.swift */,
@@ -154,6 +157,7 @@
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/Base.lproj/Main.storyboard b/foray/Base.lproj/Main.storyboard
index a655965..6e8fa72 100644
--- a/foray/Base.lproj/Main.storyboard
+++ b/foray/Base.lproj/Main.storyboard
@@ -3,8 +3,6 @@
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
- <capability name="Safe area layout guides" minToolsVersion="9.0"/>
- <capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@@ -48,49 +46,7 @@
<scene sceneID="bHL-Pf-Ers">
<objects>
<viewController id="8GL-ME-btj" customClass="ForayDetailViewController" customModule="foray" customModuleProvider="target" sceneMemberID="viewController">
- <view key="view" contentMode="scaleToFill" id="xcn-ik-xzR">
- <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
- <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
- <subviews>
- <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="aBf-Zs-Jkz">
- <rect key="frame" x="0.0" y="178" width="414" height="200"/>
- <constraints>
- <constraint firstAttribute="height" constant="200" id="hSS-D1-lO9"/>
- </constraints>
- </imageView>
- <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aP2-hq-U5p">
- <rect key="frame" x="16" y="104" width="382" height="42"/>
- <fontDescription key="fontDescription" type="boldSystem" pointSize="35"/>
- <nil key="textColor"/>
- <nil key="highlightedColor"/>
- </label>
- <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" numberOfLines="6" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="odL-rc-3m5">
- <rect key="frame" x="16" y="410" width="382" height="20.5"/>
- <fontDescription key="fontDescription" type="system" pointSize="17"/>
- <nil key="textColor"/>
- <nil key="highlightedColor"/>
- </label>
- </subviews>
- <viewLayoutGuide key="safeArea" id="w1j-x8-sDP"/>
- <color key="backgroundColor" systemColor="systemBackgroundColor"/>
- <constraints>
- <constraint firstItem="w1j-x8-sDP" firstAttribute="trailing" secondItem="odL-rc-3m5" secondAttribute="trailing" constant="16" id="2fw-Ji-Nhl"/>
- <constraint firstItem="aBf-Zs-Jkz" firstAttribute="top" secondItem="aP2-hq-U5p" secondAttribute="bottom" constant="32" id="2gC-T0-uyU"/>
- <constraint firstItem="odL-rc-3m5" firstAttribute="leading" secondItem="w1j-x8-sDP" secondAttribute="leading" constant="16" id="4GW-Aj-ulz"/>
- <constraint firstItem="odL-rc-3m5" firstAttribute="top" secondItem="aBf-Zs-Jkz" secondAttribute="bottom" constant="32" id="C26-Lc-Ghw"/>
- <constraint firstItem="aBf-Zs-Jkz" firstAttribute="trailing" secondItem="w1j-x8-sDP" secondAttribute="trailing" id="CYY-Ga-lIM"/>
- <constraint firstItem="aBf-Zs-Jkz" firstAttribute="leading" secondItem="w1j-x8-sDP" secondAttribute="leading" id="Pat-F1-1hL"/>
- <constraint firstItem="aP2-hq-U5p" firstAttribute="leading" secondItem="w1j-x8-sDP" secondAttribute="leading" constant="16" id="YsS-R7-Ov5"/>
- <constraint firstItem="w1j-x8-sDP" firstAttribute="trailing" secondItem="aP2-hq-U5p" secondAttribute="trailing" constant="16" id="i7K-yP-UW1"/>
- <constraint firstItem="aP2-hq-U5p" firstAttribute="top" secondItem="w1j-x8-sDP" secondAttribute="top" constant="16" id="lT8-FD-Axc"/>
- </constraints>
- </view>
<navigationItem key="navigationItem" title="Details" id="bIX-Sf-Bkw"/>
- <connections>
- <outlet property="detailLabel" destination="odL-rc-3m5" id="07Y-K3-w9b"/>
- <outlet property="imageView" destination="aBf-Zs-Jkz" id="qiy-cQ-1sV"/>
- <outlet property="titleLabel" destination="aP2-hq-U5p" id="6r0-Xo-1WF"/>
- </connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="MQj-7U-nIV" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
@@ -99,7 +55,7 @@
<!--Foray-->
<scene sceneID="Yrg-KY-tVC">
<objects>
- <navigationController title="Foray" automaticallyAdjustsScrollViewInsets="NO" id="c0a-IT-Aiw" sceneMemberID="viewController">
+ <navigationController title="Foray" extendedLayoutIncludesOpaqueBars="YES" automaticallyAdjustsScrollViewInsets="NO" id="c0a-IT-Aiw" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="YMv-Mh-Wv2">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
@@ -115,9 +71,4 @@
<point key="canvasLocation" x="-462.31884057971018" y="51.5625"/>
</scene>
</scenes>
- <resources>
- <systemColor name="systemBackgroundColor">
- <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
- </systemColor>
- </resources>
</document>
diff --git a/foray/ForayDetailViewController.swift b/foray/ForayDetailViewController.swift
index eb5b577..bac2dfd 100644
--- a/foray/ForayDetailViewController.swift
+++ b/foray/ForayDetailViewController.swift
@@ -10,31 +10,19 @@ import UIKit
class ForayDetailViewController: UIViewController {
var selectedItem: PenguinItem!
-
- @IBOutlet weak var titleLabel: UILabel!
- @IBOutlet weak var imageView: UIImageView!
- @IBOutlet weak var detailLabel: UILabel!
+
+ let detailView: ForayNewDetailView = ForayNewDetailView(frame: CGRect.zero)
override func viewDidLoad() {
super.viewDidLoad()
-
- titleLabel.text = selectedItem.name
- imageView.image = UIImage(named: selectedItem.id)
- detailLabel.text = "Type: "
- switch selectedItem.type {
- case .item:
- detailLabel.text! += "Item"
- case .quest:
- detailLabel.text! += "Quest"
- imageView.image = UIImage(named: "spy")
- }
-
- detailLabel.text! += "\nID: " + selectedItem.id
+ self.view.backgroundColor = .systemBackground
- let dateFormatter = DateFormatter()
- dateFormatter.dateFormat = "yyyy-MM-dd"
- detailLabel.text! += "\nReleased: " + dateFormatter.string(from: selectedItem.releaseDate)
+ detailView.setSelectedItem(selectedItem: selectedItem)
+ self.view.addSubview(detailView)
+ detailView.snp.makeConstraints { (make) in
+ make.edges.equalTo(self.view.snp.margins)
+ }
}
}
diff --git a/foray/ForayNewDetailView.swift b/foray/ForayNewDetailView.swift
new file mode 100644
index 0000000..e7d7dbf
--- /dev/null
+++ b/foray/ForayNewDetailView.swift
@@ -0,0 +1,85 @@
+//
+// 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
+ 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(8)
+ make.leading.trailing.equalToSuperview()
+ make.height.equalTo(150)
+ }
+ descLabel.snp.makeConstraints { (make) in
+ make.top.equalTo(itemImageView.snp.bottom).offset(8)
+ 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)
+ }
+}