Skip to content

Commit

Permalink
Merge pull request #2 from CristianDRM/master
Browse files Browse the repository at this point in the history
Support to CPF and CNPJ
  • Loading branch information
CristianDRM committed Jun 26, 2017
2 parents b48a500 + 936234c commit e3d8c93
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 311 deletions.
99 changes: 87 additions & 12 deletions Example/GeneralFormatter/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,101 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="sZE-na-M02">
<rect key="frame" x="87.5" y="318" width="200" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="can-nv-0kY"/>
<constraint firstAttribute="height" constant="30" id="vAZ-uA-fNu"/>
</constraints>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="CPF" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ITp-Om-IbF">
<rect key="frame" x="32" y="42" width="311" height="20.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="sZE-na-M02">
<rect key="frame" x="32" y="71" width="311" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="7Ky-kq-XjE"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="CNPJ" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Fpw-Ic-ixM">
<rect key="frame" x="32" y="123" width="311" height="20.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="f8s-i1-kzC">
<rect key="frame" x="32" y="151" width="311" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="J4p-D2-7y2"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="CEP" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="u11-vI-66Q">
<rect key="frame" x="32" y="198" width="311" height="20.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="OsR-v5-8KU">
<rect key="frame" x="32" y="227" width="311" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="vef-X5-dzO"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="CPFCNPJ" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TAc-CD-JXg">
<rect key="frame" x="32" y="272" width="311" height="20.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Dip-ZF-mWU">
<rect key="frame" x="32" y="293" width="311" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="0ME-5S-8xh"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Phone" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hI6-Lt-tHB">
<rect key="frame" x="32" y="350" width="311" height="20.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="E6H-mB-TDE">
<rect key="frame" x="32" y="379" width="311" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="kLN-8z-EAl"/>
</connections>
</textField>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="sZE-na-M02" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="HEM-dj-G8m"/>
<constraint firstItem="sZE-na-M02" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" id="y0z-Nl-rue"/>
</constraints>
<color key="backgroundColor" red="0.0039215688589999999" green="1" blue="0.68627452850000004" alpha="1" colorSpace="calibratedRGB"/>
</view>
<connections>
<outlet property="txtCEP" destination="OsR-v5-8KU" id="2dv-9h-BZK"/>
<outlet property="txtCNPJ" destination="f8s-i1-kzC" id="bFW-Gd-PtF"/>
<outlet property="txtCPF" destination="sZE-na-M02" id="z5v-NU-Hna"/>
<outlet property="txtCPFCNPJ" destination="Dip-ZF-mWU" id="v03-M1-XLe"/>
<outlet property="txtPhone" destination="E6H-mB-TDE" id="F0W-fu-Zis"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" id="T6Y-uk-yg5">
Expand All @@ -51,7 +126,7 @@
<textInputTraits key="textInputTraits"/>
</textField>
</objects>
<point key="canvasLocation" x="32.799999999999997" y="36.431784107946029"/>
<point key="canvasLocation" x="17" y="71"/>
</scene>
</scenes>
</document>
22 changes: 18 additions & 4 deletions Example/GeneralFormatter/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,31 @@ import GeneralFormatter

class ViewController: UIViewController {

@IBOutlet weak var txtCPF: UITextField!
@IBOutlet weak var txtCNPJ: UITextField!
@IBOutlet weak var txtCPFCNPJ: UITextField!
@IBOutlet weak var txtCEP: UITextField!
@IBOutlet weak var txtPhone: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

}

}

extension ViewController: UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let formatter = GeneralFormatter(type: .cpfCnpj)
return formatter.formatTextField(textField, shouldChangeCharactersIn: range, replacementString: string)
if textField == txtCPF {
return GeneralFormatter.cpf.formatTextField(_: textField, shouldChangeCharactersIn: range, replacementString: string)
} else if textField == txtCNPJ {
return GeneralFormatter.cnpj.formatTextField(_: textField, shouldChangeCharactersIn: range, replacementString: string)
} else if textField == txtCPFCNPJ {
return GeneralFormatter.cpfCnpj.formatTextField(_: textField, shouldChangeCharactersIn: range, replacementString: string)
} else if textField == txtCEP {
return GeneralFormatter.cep.formatTextField(_: textField, shouldChangeCharactersIn: range, replacementString: string)
} else if textField == txtPhone {
return GeneralFormatter.phone.formatTextField(_: textField, shouldChangeCharactersIn: range, replacementString: string)
}
return true
}
}

4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- GeneralFormatter (1.0.0)
- GeneralFormatter (1.1.1)

DEPENDENCIES:
- GeneralFormatter (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: ../

SPEC CHECKSUMS:
GeneralFormatter: b7323404c723a041a08895a7fcb7db14b18e7fb8
GeneralFormatter: 433568fb8307644803b5f058ab9fd2db54e92c99

PODFILE CHECKSUM: ec4a3bc57021d94ba554319e839e0fcdacabf704

Expand Down
12 changes: 6 additions & 6 deletions Example/Pods/Local Podspecs/GeneralFormatter.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e3d8c93

Please sign in to comment.