Skip to content

Commit

Permalink
Add basic form and text field
Browse files Browse the repository at this point in the history
  • Loading branch information
DipanshKhandelwal committed Oct 19, 2019
1 parent 8de5385 commit a573131
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
50 changes: 45 additions & 5 deletions food-tracker-app/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,24 +1,64 @@
<?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="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--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="ViewController" customModule="food_tracker_app" 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="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="NuG-Lf-rXT">
<rect key="frame" x="20" y="64" width="374" height="100.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Meal Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uNi-bg-8bh">
<rect key="frame" x="0.0" y="0.0" width="86.5" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Enter meal name" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="twI-5p-iym">
<rect key="frame" x="0.0" y="28.5" width="374" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="done" enablesReturnKeyAutomatically="YES"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cum-gC-Me4">
<rect key="frame" x="0.0" y="70.5" width="151" height="30"/>
<state key="normal" title="Set Default Label Text"/>
<connections>
<action selector="setDefaultLabelText:" destination="BYZ-38-t0r" eventType="touchUpInside" id="tfA-QK-75e"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="twI-5p-iym" firstAttribute="leading" secondItem="NuG-Lf-rXT" secondAttribute="leading" id="itL-Vm-Ws8"/>
<constraint firstAttribute="trailing" secondItem="twI-5p-iym" secondAttribute="trailing" id="x0v-j3-vRG"/>
</constraints>
</stackView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="NuG-Lf-rXT" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="20" id="1OT-Qc-hU5"/>
<constraint firstItem="NuG-Lf-rXT" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" constant="-20" id="BEA-qP-BLI"/>
<constraint firstItem="NuG-Lf-rXT" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="20" id="P4R-TB-jyQ"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="mealNameLabel" destination="uNi-bg-8bh" id="5rP-pi-mYt"/>
<outlet property="nameTextField" destination="twI-5p-iym" id="ego-jW-u8a"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="137.68115942028987" y="125.89285714285714"/>
</scene>
</scenes>
</document>
27 changes: 23 additions & 4 deletions food-tracker-app/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,32 @@

import UIKit

class ViewController: UIViewController {

class ViewController: UIViewController, UITextFieldDelegate {

//MARK: Properties
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var mealNameLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.

// Handle the text field’s user input through delegate callbacks.
nameTextField.delegate = self
}

//MARK: UITextFieldDelegate
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// Hide the keyboard.
textField.resignFirstResponder()
return true
}

func textFieldDidEndEditing(_ textField: UITextField) {
mealNameLabel.text = textField.text
}

//MARK: Actions
@IBAction func setDefaultLabelText(_ sender: UIButton) {
mealNameLabel.text = "Default Text"
}
}

0 comments on commit a573131

Please sign in to comment.