Implement UI for HistoryViewController

This commit is contained in:
CypherPoet 2019-01-22 01:01:39 -05:00
parent c1494ef483
commit b70ac41d4e
3 changed files with 66 additions and 2 deletions

View File

@ -81,15 +81,64 @@
<view key="view" contentMode="scaleToFill" id="3QE-Zj-Q0o">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="All-Time Asteroid Counts" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WfA-Wu-UxE">
<rect key="frame" x="25" y="53" width="324" height="95"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle0"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5qp-Sw-iWB">
<rect key="frame" x="54" y="510" width="266" height="63"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Near-Earth Objects" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tJb-aL-7aL">
<rect key="frame" x="35" y="189" width="304" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="0" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0aF-YV-Qsn">
<rect key="frame" x="35" y="235" width="304" height="29"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="24"/>
<color key="textColor" red="0.45880425499999999" green="0.42457667529999998" blue="0.85103040929999996" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Close Approaches" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iAw-ss-DNd">
<rect key="frame" x="35" y="302" width="304" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="0" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0HH-U5-rfN">
<rect key="frame" x="35" y="350" width="304" height="29"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="24"/>
<color key="textColor" red="0.98754758880000004" green="0.35643531880000001" blue="0.43980186630000001" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="IFX-y5-6Wy"/>
</view>
<tabBarItem key="tabBarItem" systemItem="history" id="0hS-R7-7xW"/>
<navigationItem key="navigationItem" id="c4g-Fz-UDp"/>
<connections>
<outlet property="closeApproachCountLabel" destination="0HH-U5-rfN" id="3oV-ZD-afl"/>
<outlet property="jplSourceLabel" destination="5qp-Sw-iWB" id="AwS-4x-XL9"/>
<outlet property="neoCountLabel" destination="0aF-YV-Qsn" id="bN4-cD-QeR"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="3LH-X2-evH" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="857" y="833"/>
<point key="canvasLocation" x="856.79999999999995" y="832.53373313343332"/>
</scene>
<!--Tab Bar Controller-->
<scene sceneID="N6K-lR-yZX">

View File

@ -9,9 +9,14 @@
import UIKit
class HistoryViewController: UIViewController {
@IBOutlet weak var neoCountLabel: UILabel!
@IBOutlet weak var closeApproachCountLabel: UILabel!
@IBOutlet weak var jplSourceLabel: UILabel!
let apiURL = "https://api.nasa.gov/neo/rest/v1/stats?api_key=DEMO_KEY"
var historyData: NEOHistory?
override func viewDidLoad() {
super.viewDidLoad()
@ -24,6 +29,7 @@ class HistoryViewController: UIViewController {
if let url = URL(string: apiURL) {
if let requestData = try? Data(contentsOf: url) {
historyData = parseHistoryData(data: requestData)
updateUIOnLoad()
return
}
@ -50,4 +56,13 @@ class HistoryViewController: UIViewController {
present(alertController, animated: true)
}
func updateUIOnLoad() {
if let historyData = historyData {
neoCountLabel.text = String(historyData.nearEarthObjectCount)
closeApproachCountLabel.text = String(historyData.closeApproachCount)
jplSourceLabel.text = historyData.source
}
}
}

View File

@ -20,7 +20,7 @@ struct NEOHistory: Codable {
case nearEarthObjectCount = "near_earth_object_count"
case closeApproachCount = "close_approach_count"
case lastUpdated = "last_updated"
case source = "source"
case source
case jplURL = "nasa_jpl_url"
}
}