Skip to content

Commit

Permalink
master: Updated the example project with multiple text fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
ams-twelker committed Mar 4, 2017
1 parent 0cf424f commit a17977a
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Example/RAGTextField.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; };
BFA09EC61E6B70A2001A994B /* PillView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFA09EC51E6B70A2001A994B /* PillView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -45,6 +46,7 @@
B3D34898E71706E17E1A9690 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
B82FD5A4EA5D2C97A0EE3C58 /* Pods-RAGTextField_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RAGTextField_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RAGTextField_Tests/Pods-RAGTextField_Tests.debug.xcconfig"; sourceTree = "<group>"; };
BDAFF24CEB744F384BD1CA35 /* Pods_RAGTextField_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RAGTextField_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
BFA09EC51E6B70A2001A994B /* PillView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PillView.swift; sourceTree = "<group>"; };
C40CD81EE62A049C59BA2C8B /* Pods-RAGTextField_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RAGTextField_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-RAGTextField_Example/Pods-RAGTextField_Example.release.xcconfig"; sourceTree = "<group>"; };
FB0BEFBFFFA6FDCAE8495263 /* Pods-RAGTextField_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RAGTextField_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-RAGTextField_Tests/Pods-RAGTextField_Tests.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -103,11 +105,12 @@
isa = PBXGroup;
children = (
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
607FACDC1AFB9204008FA782 /* Images.xcassets */,
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
BFA09EC51E6B70A2001A994B /* PillView.swift */,
607FACD31AFB9204008FA782 /* Supporting Files */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
);
name = "Example for RAGTextField";
path = RAGTextField;
Expand Down Expand Up @@ -362,6 +365,7 @@
buildActionMask = 2147483647;
files = (
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
BFA09EC61E6B70A2001A994B /* PillView.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
111 changes: 110 additions & 1 deletion Example/RAGTextField/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,117 @@
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Placeholder" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="ukl-8O-UHI" userLabel="Scaled placeholder and hint" customClass="RAGTextField" customModule="RAGTextField">
<rect key="frame" x="16" y="52" width="343" height="63"/>
<color key="textColor" red="0.29019609093666077" green="0.29019609093666077" blue="0.29019609093666077" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="hint" value="Hint or error text (optional)"/>
<userDefinedRuntimeAttribute type="number" keyPath="placeholderScaleWhenEditing">
<real key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="scaledPlaceholderOffset">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="horizontalTextPadding">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="verticalTextPadding">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="hintColor">
<color key="value" red="0.40000000596046448" green="0.80000001192092896" blue="0.20000000298023224" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="placeholderColor">
<color key="value" red="0.60784316062927246" green="0.60784316062927246" blue="0.60784316062927246" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="4"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="cQ3-UV-SBj"/>
</connections>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="Text" placeholder="Scaled placeholder" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Prq-1L-FRX" userLabel="Scaled placeholder" customClass="RAGTextField" customModule="RAGTextField">
<rect key="frame" x="16" y="147" width="343" height="43"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<textInputTraits key="textInputTraits"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="placeholderScaleWhenEditing">
<real key="value" value="0.65000000000000002"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="scaledPlaceholderOffset">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="horizontalTextPadding">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="verticalTextPadding">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="hintColor">
<color key="value" red="0.40000000600000002" green="0.80000001190000003" blue="0.20000000300000001" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="placeholderColor">
<color key="value" red="0.96078431606292725" green="0.65098041296005249" blue="0.13725490868091583" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="VHw-SG-yjM"/>
</connections>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Enter some text!" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="3tr-Ai-k5j" userLabel="Plain" customClass="RAGTextField" customModule="RAGTextField">
<rect key="frame" x="16" y="222" width="343" height="41.5"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<textInputTraits key="textInputTraits"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="placeholderScaleWhenEditing">
<real key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="scaledPlaceholderOffset">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="horizontalTextPadding">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="verticalTextPadding">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="hintColor">
<color key="value" red="0.40000000600000002" green="0.80000001190000003" blue="0.20000000300000001" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="placeholderColor">
<color key="value" red="0.96078431610000004" green="0.65098041299999998" blue="0.13725490870000001" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="c5w-Ro-B1k"/>
</connections>
</textField>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="3tr-Ai-k5j" firstAttribute="leading" secondItem="ukl-8O-UHI" secondAttribute="leading" id="1Yx-db-Qp8"/>
<constraint firstAttribute="trailing" secondItem="ukl-8O-UHI" secondAttribute="trailing" constant="16" id="5L8-ye-67h"/>
<constraint firstItem="Prq-1L-FRX" firstAttribute="top" secondItem="ukl-8O-UHI" secondAttribute="bottom" constant="32" id="7ul-Yk-IpB"/>
<constraint firstItem="Prq-1L-FRX" firstAttribute="trailing" secondItem="ukl-8O-UHI" secondAttribute="trailing" id="NOg-bN-O6F"/>
<constraint firstItem="Prq-1L-FRX" firstAttribute="leading" secondItem="ukl-8O-UHI" secondAttribute="leading" id="Pkv-Xg-Npr"/>
<constraint firstItem="3tr-Ai-k5j" firstAttribute="top" secondItem="Prq-1L-FRX" secondAttribute="bottom" constant="32" id="QAe-6g-BNz"/>
<constraint firstItem="ukl-8O-UHI" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="16" id="aMc-fZ-dSs"/>
<constraint firstItem="ukl-8O-UHI" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="32" id="bHl-C3-FCZ"/>
<constraint firstItem="3tr-Ai-k5j" firstAttribute="trailing" secondItem="ukl-8O-UHI" secondAttribute="trailing" id="rYd-RK-uyS"/>
</constraints>
</view>
<connections>
<outlet property="placeholderAndHintTextField" destination="ukl-8O-UHI" id="H47-UD-TNe"/>
<outlet property="placeholderTextField" destination="Prq-1L-FRX" id="exw-2x-cuw"/>
<outlet property="plainTextField" destination="3tr-Ai-k5j" id="i3L-MT-EFO"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
Expand Down
19 changes: 19 additions & 0 deletions Example/RAGTextField/PillView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// PillView.swift
// RAGTextField
//
// Created by Reimar Twelker on 23.02.17.
// Copyright © 2017 Reimar Twelker. All rights reserved.
//

import UIKit

@IBDesignable class PillView: UIView {

override func layoutSubviews() {
super.layoutSubviews()

let cornerRadius = floor(0.5 * min(bounds.width, bounds.height))
layer.cornerRadius = cornerRadius
}
}
77 changes: 77 additions & 0 deletions Example/RAGTextField/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,88 @@
//

import UIKit
import RAGTextField

private enum Constants {
static let horizontalPadding = CGFloat(8.0)
static let verticalPadding = CGFloat(4.0)
}

class ViewController: UIViewController {

@IBOutlet weak var placeholderAndHintTextField: RAGTextField! {
didSet {
let bgView = PillView()
bgView.backgroundColor = UIColor.black.withAlphaComponent(0.1)
placeholderAndHintTextField.textBackgroundView = bgView

placeholderAndHintTextField.horizontalTextPadding = Constants.horizontalPadding
placeholderAndHintTextField.verticalTextPadding = Constants.verticalPadding

placeholderAndHintTextField.placeholderMode = .scalesWhenNotEmpty
placeholderAndHintTextField.scaledPlaceholderOffset = 2.0
}
}

@IBOutlet weak var placeholderTextField: RAGTextField! {
didSet {
let bgView = PillView()
bgView.backgroundColor = UIColor.black.withAlphaComponent(0.1)
placeholderTextField.textBackgroundView = bgView

placeholderTextField.horizontalTextPadding = Constants.horizontalPadding
placeholderTextField.verticalTextPadding = Constants.verticalPadding

placeholderTextField.placeholderMode = .scalesWhenEditing
placeholderTextField.scaledPlaceholderOffset = 2.0
}
}

@IBOutlet weak var plainTextField: RAGTextField! {
didSet {
let bgView = PillView()
bgView.backgroundColor = UIColor.black.withAlphaComponent(0.1)
plainTextField.textBackgroundView = bgView

plainTextField.horizontalTextPadding = Constants.horizontalPadding
plainTextField.verticalTextPadding = Constants.verticalPadding

plainTextField.placeholderMode = .simple
}
}

fileprivate var orderedTextFields = [UIResponder]()

override func viewDidLoad() {
super.viewDidLoad()

orderedTextFields = [placeholderAndHintTextField, placeholderTextField, plainTextField]
}

fileprivate func nextResponder(after responder: UIResponder) -> UIResponder? {
switch responder {
case placeholderAndHintTextField:
return placeholderTextField
case placeholderTextField:
return plainTextField
case plainTextField:
return nil
default:
return nil
}
}
}

extension ViewController: UITextFieldDelegate {

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()

return true
}

func textFieldDidEndEditing(_ textField: UITextField) {
let nextFirstResponder = nextResponder(after: textField)
nextFirstResponder?.becomeFirstResponder()
}
}

0 comments on commit a17977a

Please sign in to comment.