These are chat archives for correa-brian/milkshake

14th
Jun 2016
Katrina
@katrinar
Jun 14 2016 19:52 UTC
//
//  CTCreatePlaceViewController.swift
//  chat-ios
//
//  Created by Katrina Rodriguez on 6/14/16.
//  Copyright © 2016 Kat. All rights reserved.
//

import UIKit

class CTCreatePlaceViewController: CTViewController, UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource {

    var textFields = Array<UITextField>()
    var statePicker: UIPickerView!
    var states =  [ "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY" ]

    override func loadView() {
        let frame = UIScreen.mainScreen().bounds
        let view = UIView(frame: frame)
        view.backgroundColor = UIColor.lightGrayColor()

        let btnCancel = UIButton(type: .Custom)
        btnCancel.frame = CGRect(x: 20, y: 20, width: 100, height: 32)
        btnCancel.setTitle("Cancel", forState: .Normal)
        btnCancel.setTitleColor(.whiteColor(), forState: .Normal)
        btnCancel.addTarget(self,
                            action: #selector(CTCreatePlaceViewController.exit),
                            forControlEvents: .TouchUpInside)
        view.addSubview(btnCancel)

        let padding = CGFloat(20)
        let width = frame.size.width-2*padding
        let height = CGFloat(32)
        var y = CGFloat(120)
        let font = UIFont(name: "Heiti SC", size: 18)

        let fieldNames = ["Name", "Address", "City", "State", "Password"]
        for fieldName in fieldNames {

            let field = UITextField(frame: CGRect(x: padding, y: y, width: width, height: height))
            field.delegate = self
            field.placeholder = fieldName
            field.font = font
            field.autocorrectionType = .No
            let isPassword = (fieldName == "Password")
            field.secureTextEntry = (isPassword)
            field.returnKeyType = (isPassword) ? .Join : .Next
            let line = UIView(frame: CGRect(x: 0, y: height-1, width: width, height: 1))
            line.backgroundColor = .whiteColor()
            field.addSubview(line)
            view.addSubview(field)
            self.textFields.append(field)
            y += height+padding
        }

         self.statePicker = UIPickerView(frame: CGRect(x: 0, y: frame.size.height, width: frame.size.width, height: 160))
        self.statePicker.backgroundColor = .whiteColor()
        self.statePicker.delegate = self
        self.statePicker.dataSource = self
        view.addSubview(statePicker)
        self.view = view
    }



    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    //MARK: - PickerViewDelegate and Datasource
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1
    }


   func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return self.states.count
    }


    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return self.states[row]
    }

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        print("didSelectRow \(row)")
        for textField in self.textFields{
            if (textField.placeholder == "State"){
                textField.text = self.states[row]
                UIView.animateWithDuration(0.35,
                                           animations: {
                                            var frame = self.statePicker.frame
                                            frame.origin.y = self.view.frame.size.height
                                            self.statePicker.frame = frame
                    }, completion: nil)

                let index = self.textFields.