Skip to content

Commit

Permalink
complete front end ui
Browse files Browse the repository at this point in the history
  • Loading branch information
samwise2 committed Nov 28, 2019
1 parent b7ee184 commit d5a60e9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</switch>
<pickerView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Pmf-4L-Szk">
<rect key="frame" x="16" y="0.0" width="292" height="198"/>
<rect key="frame" x="180" y="207" width="124" height="43"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/>
</pickerView>
Expand Down
49 changes: 33 additions & 16 deletions home security device/home security device/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

class ViewController: UIViewController {
private let dataSource = ["apple", "bannana", "bob"]
private let dataSource = ["At Home", "Sleeping", "Away"]

var counter = 0
@IBOutlet weak var DoorSwitch: UISwitch!
Expand All @@ -19,33 +19,33 @@ class ViewController: UIViewController {
@IBOutlet weak var picker: UIPickerView!


var button = dropDownBtn()
//var button = dropDownBtn()

override func viewDidLoad() {
super.viewDidLoad()
picker.dataSource = self
picker.delegate = self

//Configure the button
button = dropDownBtn.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
button.setTitle("At Home", for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
//button = dropDownBtn.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
//button.setTitle("At Home", for: .normal)
//button.translatesAutoresizingMaskIntoConstraints = false

//Add Button to the View Controller
self.view.addSubview(button)
//self.view.addSubview(button)
//button Constraints
NSLayoutConstraint(item: button, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leadingMargin, multiplier: 1.0, constant: 180.0).isActive = true
NSLayoutConstraint(item: button, attribute: .bottom, relatedBy: .equal, toItem: view, attribute:.bottomMargin, multiplier: 1.0, constant:-310.0).isActive = true
// NSLayoutConstraint(item: button, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leadingMargin, multiplier: 1.0, constant: 180.0).isActive = true
// NSLayoutConstraint(item: button, attribute: .bottom, relatedBy: .equal, toItem: view, attribute:.bottomMargin, multiplier: 1.0, constant:-310.0).isActive = true
//button.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
//button.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
//var xPos = 50.0
//var yPos = 50.0
//button.frame = CGRectMake(CGFloat(xPos),CGFloat(yPos), 50 .width)
button.widthAnchor.constraint(equalToConstant: 100).isActive = true
button.heightAnchor.constraint(equalToConstant: 50).isActive = true
// button.widthAnchor.constraint(equalToConstant: 100).isActive = true
// button.heightAnchor.constraint(equalToConstant: 50).isActive = true

//Set the drop down menu's options
button.dropView.dropDownOptions = ["At Home", "Sleeping", "Away"]
//button.dropView.dropDownOptions = ["At Home", "Sleeping", "Away"]
// Do any additional setup after loading the view.
}

Expand All @@ -66,7 +66,8 @@ class ViewController: UIViewController {
}

extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
func numberOfComponents(in pickerView: UIPickerView)
-> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
Expand All @@ -75,9 +76,25 @@ extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource {
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
//detailLabel.text = dataSource[row]
//picks given thing
if dataSource[row] == "apple"
if dataSource[row] == "Away"
{
BuzzerSwitch.isOn = true
background.image = UIImage(named: "secured")
BuzzerSwitch.isOn=true;
DoorSwitch.isOn = true;
MotionSwitch.isOn = true;
}
if dataSource[row] == "At Home"
{
background.image = UIImage(named: "secured")
BuzzerSwitch.isOn = false
DoorSwitch.isOn = true
MotionSwitch.isOn = false;
}
if dataSource[row] == "Sleeping" {
background.image = UIImage(named: "secured")
DoorSwitch.isOn = true
MotionSwitch.isOn = true
BuzzerSwitch.isOn = false
}
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
Expand All @@ -86,7 +103,7 @@ extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource {

}

protocol dropDownProtocol {
/*protocol dropDownProtocol {
func dropDownPressed(string : String)
}

Expand Down Expand Up @@ -227,6 +244,6 @@ class dropDownView: UIView, UITableViewDelegate, UITableViewDataSource {
self.tableView.deselectRow(at: indexPath, animated: true)
}

}
}*/


0 comments on commit d5a60e9

Please sign in to comment.