Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions SwiftyCodeView/Classes/SwiftyCodeView/SwiftyCodeItemView.xib
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.3" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -17,38 +15,34 @@
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8eU-ou-C0S">
<rect key="frame" x="0.0" y="0.0" width="51" height="58"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="51" id="cS3-og-EIV"/>
<constraint firstAttribute="height" constant="58" id="qYP-qF-2wV"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="4"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<textField opaque="NO" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="0" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="yGk-IE-oMU" customClass="SwiftyCodeTextField" customModule="SwiftyCodeView" customModuleProvider="target">
<rect key="frame" x="0.0" y="13" width="51" height="32"/>
<color key="textColor" red="0.0" green="0.4549019608" blue="0.47058823529999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" name="CourierNewPSMT" family="Courier New" pointSize="28"/>
<rect key="frame" x="0.0" y="0.0" width="51" height="58"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="18"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="numberPad" smartDashesType="no" smartInsertDeleteType="no" smartQuotesType="no"/>
</textField>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="yGk-IE-oMU" firstAttribute="centerY" secondItem="nHd-eh-O0u" secondAttribute="centerY" id="4OF-ow-UeP"/>
<constraint firstAttribute="bottom" secondItem="8eU-ou-C0S" secondAttribute="bottom" id="M3N-iE-2Iv"/>
<constraint firstAttribute="trailing" secondItem="8eU-ou-C0S" secondAttribute="trailing" id="PQ1-rb-zgJ"/>
<constraint firstItem="8eU-ou-C0S" firstAttribute="top" secondItem="nHd-eh-O0u" secondAttribute="top" id="hJV-zO-gTO"/>
<constraint firstItem="yGk-IE-oMU" firstAttribute="leading" secondItem="nHd-eh-O0u" secondAttribute="leading" id="iVP-On-FHn"/>
<constraint firstAttribute="trailing" secondItem="yGk-IE-oMU" secondAttribute="trailing" id="qux-La-Y2f"/>
<constraint firstItem="8eU-ou-C0S" firstAttribute="leading" secondItem="nHd-eh-O0u" secondAttribute="leading" id="zHj-iu-fqN"/>
<constraint firstAttribute="trailing" secondItem="yGk-IE-oMU" secondAttribute="trailing" id="0aT-Vz-hBs"/>
<constraint firstItem="yGk-IE-oMU" firstAttribute="top" secondItem="nHd-eh-O0u" secondAttribute="top" id="80l-tH-8oH"/>
<constraint firstAttribute="bottom" secondItem="yGk-IE-oMU" secondAttribute="bottom" id="CfF-5H-pQX"/>
<constraint firstItem="yGk-IE-oMU" firstAttribute="leading" secondItem="nHd-eh-O0u" secondAttribute="leading" id="OQ3-gW-c3N"/>
<constraint firstItem="8eU-ou-C0S" firstAttribute="leading" secondItem="nHd-eh-O0u" secondAttribute="leading" id="VNj-OM-nuI"/>
<constraint firstAttribute="trailing" secondItem="8eU-ou-C0S" secondAttribute="trailing" id="YuP-1r-I7D"/>
<constraint firstAttribute="bottom" secondItem="8eU-ou-C0S" secondAttribute="bottom" id="cHV-ew-jSc"/>
<constraint firstItem="8eU-ou-C0S" firstAttribute="top" secondItem="nHd-eh-O0u" secondAttribute="top" id="xFu-y0-suP"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="textField" destination="yGk-IE-oMU" id="2aM-Dm-Clp"/>
</connections>
<point key="canvasLocation" x="357" y="-65"/>
<point key="canvasLocation" x="356" y="-66.566716641679164"/>
</view>
</objects>
</document>
9 changes: 5 additions & 4 deletions SwiftyCodeView/Classes/SwiftyCodeView/SwiftyCodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ open class SwiftyCodeView: UIControl {
var stackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.distribution = .equalSpacing
stackView.distribution = .fillEqually
stackView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
stackView.spacing = 16.0
return stackView
}()

Expand Down Expand Up @@ -107,7 +108,7 @@ extension SwiftyCodeView: UITextFieldDelegate, SwiftyCodeTextFieldDelegate {

public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

if string == "" { //is backspace
if string == "" { // is backspace
return true
}

Expand All @@ -116,12 +117,12 @@ extension SwiftyCodeView: UITextFieldDelegate, SwiftyCodeTextFieldDelegate {
let item = stackView.arrangedSubviews[index] as! SwiftyCodeItemView
item.textField.text = string
sendActions(for: .valueChanged)
if index == length - 1 { //is last textfield
if index == length - 1 { // is last textfield
if (delegate?.codeView(sender: self, didFinishInput: self.code) ?? false) {
textField.resignFirstResponder()
}
return false
}
}

_ = stackView.arrangedSubviews[index + 1].becomeFirstResponder()
}
Expand Down