Skip to content

Commit

Permalink
• build ParkingSignView • example project
Browse files Browse the repository at this point in the history
  • Loading branch information
KPR7168 committed May 24, 2018
1 parent 46a661a commit 2fa7cb0
Show file tree
Hide file tree
Showing 14 changed files with 775 additions and 23 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0
103 changes: 99 additions & 4 deletions Example/ParkingSignView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina5_9" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -18,13 +18,108 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Duration:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QW1-Bh-HtG">
<rect key="frame" x="16" y="53" width="70" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<slider opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="1" minValue="1" maxValue="24" translatesAutoresizingMaskIntoConstraints="NO" id="dMY-9P-stk">
<rect key="frame" x="92" y="48" width="269" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="slider:" destination="vXZ-lx-hvc" eventType="valueChanged" id="95k-Ab-ven"/>
</connections>
</slider>
<segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="B5P-Hq-7Ip">
<rect key="frame" x="16" y="85" width="281" height="29"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<segments>
<segment title="Hour"/>
<segment title="Minute"/>
</segments>
<connections>
<action selector="unitSwitch:" destination="vXZ-lx-hvc" eventType="valueChanged" id="E1Z-ML-FH0"/>
</connections>
</segmentedControl>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aXL-ay-HAG">
<rect key="frame" x="312" y="85" width="49" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="freeSwitch:" destination="vXZ-lx-hvc" eventType="valueChanged" id="b0h-6S-kII"/>
</connections>
</switch>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="NbZ-jc-Jkh">
<rect key="frame" x="16" y="133" width="343" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<action selector="textFieldInput:" destination="vXZ-lx-hvc" eventType="editingDidBegin" id="iQs-sb-kvr"/>
</connections>
</textField>
<textField opaque="NO" tag="1" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="1qN-1Z-aie">
<rect key="frame" x="16" y="171" width="343" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<action selector="textFieldInput:" destination="vXZ-lx-hvc" eventType="editingDidBegin" id="s8q-Dt-jGx"/>
</connections>
</textField>
<textField opaque="NO" tag="2" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="qvM-Y5-djF">
<rect key="frame" x="16" y="209" width="343" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<action selector="textFieldInput:" destination="vXZ-lx-hvc" eventType="editingDidBegin" id="gDP-W2-pOP"/>
</connections>
</textField>
<textField opaque="NO" tag="3" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="fTc-jE-81j">
<rect key="frame" x="16" y="247" width="343" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<action selector="textFieldInput:" destination="vXZ-lx-hvc" eventType="editingDidBegin" id="2vu-jf-Oyd"/>
</connections>
</textField>
<slider opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1000" translatesAutoresizingMaskIntoConstraints="NO" id="PXb-s1-1Uk">
<rect key="frame" x="14" y="694" width="347" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="width:" destination="vXZ-lx-hvc" eventType="valueChanged" id="TFd-i7-jNL"/>
</connections>
</slider>
<slider opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1000" translatesAutoresizingMaskIntoConstraints="NO" id="FMH-L3-A9z">
<rect key="frame" x="14" y="741" width="347" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<connections>
<action selector="height:" destination="vXZ-lx-hvc" eventType="valueChanged" id="jQm-kW-L19"/>
</connections>
</slider>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<connections>
<outlet property="firstFromDate" destination="NbZ-jc-Jkh" id="XCG-JL-0cm"/>
<outlet property="firstToDate" destination="1qN-1Z-aie" id="4UP-O3-6xu"/>
<outlet property="secondFromDate" destination="qvM-Y5-djF" id="PUG-ME-DSp"/>
<outlet property="secondToDate" destination="fTc-jE-81j" id="TgI-zV-BF8"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-175" y="34"/>
</scene>
</scenes>
</document>
117 changes: 111 additions & 6 deletions Example/ParkingSignView/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,129 @@
//
// ViewController.swift
// ParkingSignView
// ParkingSign
//
// Created by KPR7168 on 05/24/2018.
// Copyright (c) 2018 KPR7168. All rights reserved.
// Created by Ky Pichratanak on 21/5/18.
// Copyright © 2018 Ky Pichratanak. All rights reserved.
//

import UIKit
import ParkingSignView

class ViewController: UIViewController {

var signView: ParkingSignView!
@IBOutlet weak var firstFromDate: UITextField!
@IBOutlet weak var firstToDate: UITextField!
@IBOutlet weak var secondFromDate: UITextField!
@IBOutlet weak var secondToDate: UITextField!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

// var sampleDate = DateComponents()
// sampleDate.hour = 8
// sampleDate.minute = 30
// sampleDate.weekday = WeekDay.Monday.rawValue
//
// var sampleDate1 = DateComponents()
// sampleDate1.hour = 4
// sampleDate1.minute = 3
// sampleDate1.weekday = WeekDay.Thursday.rawValue

self.signView = ParkingSignView(duration: 1, unit: .hour)
self.signView.center = self.view.center
self.view.addSubview(signView)
}

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


@IBAction func slider(_ sender: Any) {
let slider = sender as! UISlider
self.signView.duration = Int(slider.value)
}

@IBAction func textFieldInput(_ sender: Any) {
let textInput = sender as! UITextField
let datePickerView = UIDatePicker()
datePickerView.datePickerMode = UIDatePickerMode.dateAndTime
datePickerView.tag = textInput.tag
textInput.inputView = datePickerView
datePickerView.addTarget(self, action: #selector(datePickerValueChanged(sender:)), for: UIControlEvents.valueChanged)
}

@objc func datePickerValueChanged(sender: UIDatePicker) {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .full
dateFormatter.timeStyle = .short

let dateComponent = sender.calendar.dateComponents(in: sender.calendar.timeZone, from: sender.date)

switch sender.tag {
case 0:
self.firstFromDate.text = dateFormatter.string(from: sender.date)
if self.signView.firstParkingPeriod == nil {
self.signView.firstParkingPeriod = DayComponents(fromDay: dateComponent, toDay: dateComponent)
}
else {
self.signView.firstParkingPeriod?.fromDay = dateComponent
}
case 1:
self.firstToDate.text = dateFormatter.string(from: sender.date)
if self.signView.firstParkingPeriod == nil {
self.signView.firstParkingPeriod = DayComponents(fromDay: dateComponent, toDay: dateComponent)
}
else {
self.signView.firstParkingPeriod?.toDay = dateComponent
}
case 2:
self.secondFromDate.text = dateFormatter.string(from: sender.date)
if self.signView.secondParkingPeriod == nil {
self.signView.secondParkingPeriod = DayComponents(fromDay: dateComponent, toDay: dateComponent)
}
else {
self.signView.secondParkingPeriod?.fromDay = dateComponent
}
case 3:
self.secondToDate.text = dateFormatter.string(from: sender.date)
if self.signView.secondParkingPeriod == nil {
self.signView.secondParkingPeriod = DayComponents(fromDay: dateComponent, toDay: dateComponent)
}
else {
self.signView.secondParkingPeriod?.toDay = dateComponent
}
default:
self.secondToDate.text = dateFormatter.string(from: sender.date)
}
}

@IBAction func unitSwitch(_ sender: Any) {
let unitSwitch = sender as! UISegmentedControl
if unitSwitch.selectedSegmentIndex == 0 {
self.signView.unit = .hour
}
else {
self.signView.unit = .minute
}
}

@IBAction func freeSwitch(_ sender: Any) {
let switchControl = sender as! UISwitch
self.signView.isFree = !switchControl.isOn
}

@IBAction func width(_ sender: UISlider) {
self.signView.frame = CGRect(origin: self.signView.frame.origin,
size: CGSize(width: CGFloat(sender.value), height: self.signView.frame.height))
}
@IBAction func height(_ sender: UISlider) {
self.signView.frame = CGRect(origin: self.signView.frame.origin,
size: CGSize(width: self.signView.frame.width, height: CGFloat(sender.value)))
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
}

0 comments on commit 2fa7cb0

Please sign in to comment.