Skip to content

Commit

Permalink
Add color change based on counter value
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-green-ra committed Aug 8, 2018
1 parent cb8e567 commit c61d10b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</connections>
</button>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="0" textAlignment="center" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="HSf-r4-o1w">
<rect key="frame" x="155" y="169" width="65" height="120"/>
<rect key="frame" x="155" y="273.5" width="65" height="120"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="100"/>
<textInputTraits key="textInputTraits"/>
Expand All @@ -49,14 +49,14 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="aMx-UA-9lh" secondAttribute="bottom" constant="100" id="BbZ-ne-CMd"/>
<constraint firstItem="HSf-r4-o1w" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="EaF-QS-ESS"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="S7l-Br-1ON" secondAttribute="trailing" constant="100" id="GsX-Vd-wiW"/>
<constraint firstItem="HSf-r4-o1w" firstAttribute="top" secondItem="sly-MB-2lv" secondAttribute="bottom" constant="20" id="JIE-DU-Pc4"/>
<constraint firstItem="sly-MB-2lv" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="dPZ-iS-iRJ"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="S7l-Br-1ON" secondAttribute="bottom" constant="100" id="lQt-zZ-VY8"/>
<constraint firstItem="sly-MB-2lv" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="100" id="xDH-j9-Kdj"/>
<constraint firstItem="aMx-UA-9lh" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="100" id="xb6-c6-W6P"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="S7l-Br-1ON" secondAttribute="bottom" constant="100" id="0V3-FJ-1qK"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="aMx-UA-9lh" secondAttribute="bottom" constant="100" id="0ep-b0-sml"/>
<constraint firstItem="HSf-r4-o1w" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="BV0-xr-5Di"/>
<constraint firstItem="sly-MB-2lv" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="FBd-2r-oTj"/>
<constraint firstItem="aMx-UA-9lh" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="100" id="Wax-qv-nQF"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="S7l-Br-1ON" secondAttribute="trailing" constant="100" id="fqX-da-uNk"/>
<constraint firstItem="sly-MB-2lv" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="100" id="hX5-ft-ikR"/>
<constraint firstItem="HSf-r4-o1w" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="vNZ-8Q-W5J"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
Expand Down
35 changes: 25 additions & 10 deletions ChoiceTracker/ChoiceTracker/ChoiceTracker/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,46 @@ import UIKit

class ViewController: UIViewController {

//MARK:- Outlets
@IBOutlet var choiceCountTextLabel: UITextField!

//MARK:- Actions
@IBAction func addGoodChoice(_ sender: Any) {
incrementChoice(choice: "Good")
updateUI()
}

@IBAction func addBadChoice(_ sender: Any) {
incrementChoice(choice: "Bad")
updateUI()
}

//MARK:- Template
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//choiceCountTextLabel.text = "Hi"
choiceCountTextLabel.text = String(choiceCount)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBAction func addGoodChoice(_ sender: Any) {
incrementChoice(choice: "Good")
//MARK:- UI Logic
func updateUI() {
choiceCountTextLabel.text = String(choiceCount)
colorCounter()
self.view.setNeedsDisplay()
}

@IBAction func addBadChoice(_ sender: Any) {
incrementChoice(choice: "Bad")
choiceCountTextLabel.text = String(choiceCount)
self.view.setNeedsDisplay()
func colorCounter() {
if choiceCount >= 0 {
choiceCountTextLabel.textColor = UIColor.green
} else {
choiceCountTextLabel.textColor = UIColor.red
}
}

}

0 comments on commit c61d10b

Please sign in to comment.