-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
158 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,97 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> | ||
<device id="retina6_12" orientation="portrait" appearance="light"/> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/> | ||
<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> | ||
<!--View Controller--> | ||
<!--Conversion View Controller--> | ||
<scene sceneID="tne-QT-ifu"> | ||
<objects> | ||
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController"> | ||
<viewController id="BYZ-38-t0r" customClass="ConversionViewController" customModule="WorldTrotter" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> | ||
<subviews> | ||
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="value" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="1Lc-Bd-aZ7"> | ||
<rect key="frame" x="71.666666666666686" y="67" width="250" height="85.333333333333314"/> | ||
<constraints> | ||
<constraint firstAttribute="width" constant="250" id="M0J-TX-VzK"/> | ||
</constraints> | ||
<color key="textColor" systemColor="systemOrangeColor"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="70"/> | ||
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="decimalPad"/> | ||
<connections> | ||
<action selector="fahrenheitFieldEditingChanged:" destination="BYZ-38-t0r" eventType="editingChanged" id="rn4-5I-55p"/> | ||
<outlet property="delegate" destination="BYZ-38-t0r" id="8q4-sa-PF0"/> | ||
</connections> | ||
</textField> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="degrees Fahrenheit" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ogG-ut-M6e"> | ||
<rect key="frame" x="49" y="160.33333333333334" width="295" height="43"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="36"/> | ||
<color key="textColor" red="0.88235294117647056" green="0.34509803921568627" blue="0.16078431372549018" alpha="1" colorSpace="calibratedRGB"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="is really" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Bdo-9x-GJX"> | ||
<rect key="frame" x="139.66666666666666" y="211.33333333333334" width="113.66666666666666" height="43"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="36"/> | ||
<nil key="textColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="100" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nkh-sF-v9D"> | ||
<rect key="frame" x="138" y="262.33333333333331" width="117" height="84"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="70"/> | ||
<color key="textColor" red="0.88235294117647056" green="0.34509803921568627" blue="0.16078431372549018" alpha="1" colorSpace="calibratedRGB"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="degrees Celsius" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oeK-CR-4n8"> | ||
<rect key="frame" x="73.666666666666671" y="354.33333333333331" width="245.66666666666663" height="43"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="36"/> | ||
<color key="textColor" red="0.88235294117647056" green="0.34509803921568627" blue="0.16078431372549018" alpha="1" colorSpace="calibratedRGB"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/> | ||
<color key="backgroundColor" red="0.96078431372549022" green="0.95686274509803915" blue="0.94509803921568625" alpha="1" colorSpace="calibratedRGB"/> | ||
<gestureRecognizers/> | ||
<constraints> | ||
<constraint firstItem="1Lc-Bd-aZ7" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="2qN-7X-jGg"/> | ||
<constraint firstItem="oeK-CR-4n8" firstAttribute="top" secondItem="nkh-sF-v9D" secondAttribute="bottom" constant="8" id="7Vn-Ni-ODE"/> | ||
<constraint firstItem="ogG-ut-M6e" firstAttribute="top" secondItem="1Lc-Bd-aZ7" secondAttribute="bottom" constant="8" id="H8s-IL-D4u"/> | ||
<constraint firstItem="oeK-CR-4n8" firstAttribute="centerX" secondItem="nkh-sF-v9D" secondAttribute="centerX" id="HVy-5e-dLm"/> | ||
<constraint firstItem="ogG-ut-M6e" firstAttribute="centerX" secondItem="1Lc-Bd-aZ7" secondAttribute="centerX" id="Idr-Nu-DMC"/> | ||
<constraint firstItem="Bdo-9x-GJX" firstAttribute="top" secondItem="ogG-ut-M6e" secondAttribute="bottom" constant="8" id="KFc-DK-NFL"/> | ||
<constraint firstItem="oeK-CR-4n8" firstAttribute="centerX" secondItem="ogG-ut-M6e" secondAttribute="centerX" id="QX7-ua-maY"/> | ||
<constraint firstItem="Bdo-9x-GJX" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="139.66666666666666" id="abW-3C-I8U"/> | ||
<constraint firstItem="1Lc-Bd-aZ7" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="8" id="e5x-UB-qKA"/> | ||
<constraint firstItem="nkh-sF-v9D" firstAttribute="top" secondItem="Bdo-9x-GJX" secondAttribute="bottom" constant="8" id="gKp-dK-G7t"/> | ||
<constraint firstItem="oeK-CR-4n8" firstAttribute="centerX" secondItem="Bdo-9x-GJX" secondAttribute="centerX" id="uF4-yM-fbQ"/> | ||
</constraints> | ||
<connections> | ||
<outletCollection property="gestureRecognizers" destination="U0a-uQ-sJm" appends="YES" id="POv-Qh-9Eq"/> | ||
</connections> | ||
</view> | ||
<connections> | ||
<outlet property="celsiusLabel" destination="nkh-sF-v9D" id="WQU-xD-wcy"/> | ||
<outlet property="textField" destination="1Lc-Bd-aZ7" id="huu-fR-3KY"/> | ||
</connections> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> | ||
<tapGestureRecognizer id="U0a-uQ-sJm"> | ||
<connections> | ||
<action selector="dismissKeyboard:" destination="BYZ-38-t0r" id="yJg-Fd-Z1x"/> | ||
</connections> | ||
</tapGestureRecognizer> | ||
</objects> | ||
<point key="canvasLocation" x="61.832061068702288" y="3.5211267605633805"/> | ||
</scene> | ||
</scenes> | ||
<resources> | ||
<systemColor name="systemOrangeColor"> | ||
<color red="1" green="0.58431372549019611" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | ||
</systemColor> | ||
</resources> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// ConversionViewController.swift | ||
// WorldTrotter | ||
// | ||
// Created by Xiang Xiao on 12/30/22. | ||
// | ||
|
||
import UIKit | ||
|
||
class ConversionViewController: UIViewController, UITextFieldDelegate { | ||
|
||
@IBOutlet var celsiusLabel: UILabel! | ||
@IBOutlet var textField: UITextField! | ||
var fahrenheitValue: Measurement<UnitTemperature>? { | ||
didSet { | ||
updateCelsiusLabel() | ||
} | ||
} | ||
|
||
var celsiusValue: Measurement<UnitTemperature>? { | ||
if let fahrenheitValue = fahrenheitValue { | ||
return fahrenheitValue.converted(to: .celsius) | ||
} else { | ||
return nil | ||
} | ||
} | ||
|
||
@IBAction func fahrenheitFieldEditingChanged(_ textField: UITextField) { | ||
if let text = textField.text, let value = Double(text) { | ||
fahrenheitValue = Measurement(value: value, unit: .fahrenheit) | ||
} else { | ||
fahrenheitValue = nil | ||
} | ||
} | ||
|
||
@IBAction func dismissKeyboard(_ sender: UITapGestureRecognizer) { | ||
textField.resignFirstResponder() | ||
} | ||
|
||
func updateCelsiusLabel() { | ||
if let celsiusValue = celsiusValue { | ||
celsiusLabel.text = | ||
numberFormatter.string(from: NSNumber(value: celsiusValue.value)) | ||
} else { | ||
celsiusLabel.text = "???" | ||
} | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
updateCelsiusLabel() | ||
} | ||
|
||
let numberFormatter: NumberFormatter = { | ||
let nf = NumberFormatter() | ||
nf.numberStyle = .decimal | ||
nf.minimumFractionDigits = 0 | ||
nf.maximumFractionDigits = 1 | ||
return nf | ||
}() | ||
|
||
func textField(_ textField: UITextField, | ||
shouldChangeCharactersIn range: NSRange, | ||
replacementString string: String) -> Bool { | ||
let existingTextHasDecimalSeparator = textField.text?.range(of: ".") | ||
let replacementTextHasDecimalSeparator = string.range(of: ".") | ||
|
||
if existingTextHasDecimalSeparator != nil, | ||
replacementTextHasDecimalSeparator != nil { | ||
return false | ||
} | ||
return true | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.