5 Commits

Author SHA1 Message Date
Dhaval Thanki 5dfe1f7108 Swift 4.0 Support
RTL Support
Some bug fixes
2018-03-16 16:40:21 +05:30
Dhaval Thanki 7209def338 Update README.md 2017-11-14 10:17:54 +05:30
Dhaval Thanki 27f5b20eac Update README.md 2017-11-07 15:43:34 +05:30
Dhaval Thanki 4a01c4bf1b Update README.md 2017-10-21 11:55:36 +05:30
Dhaval Thanki bfcd10ed1d Version 0.2.7 2017-10-14 15:29:58 +05:30
12 changed files with 310 additions and 88 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
Pod::Spec.new do |s|
s.name = 'DTTextField'
s.version = '0.2.6'
s.version = '0.3.0'
s.summary = 'DTTextField is UITextField library.'
s.description = <<-DESC
+85 -16
View File
@@ -24,6 +24,12 @@ public class DTTextField: UITextField {
case defaults
}
public enum DTBorderStyle{
case none
case rounded
case sqare
}
fileprivate var lblFloatPlaceholder:UILabel = UILabel()
fileprivate var lblError:UILabel = UILabel()
@@ -37,6 +43,24 @@ public class DTTextField: UITextField {
public var floatingLabelShowAnimationDuration = 0.3
public var floatingDisplayStatus:FloatingDisplayStatus = .defaults
public var dtborderStyle:DTBorderStyle = .rounded{
didSet{
switch dtborderStyle {
case .none:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.0
case .rounded:
dtLayer.cornerRadius = 4.5
dtLayer.borderWidth = 0.5
dtLayer.borderColor = borderColor.cgColor
case .sqare:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.5
dtLayer.borderColor = borderColor.cgColor
}
}
}
public var errorMessage:String = ""{
didSet{ lblError.text = errorMessage }
}
@@ -72,14 +96,14 @@ public class DTTextField: UITextField {
didSet{
guard let color = placeholderColor else { return }
attributedPlaceholder = NSAttributedString(string: placeholderFinal,
attributes: [NSForegroundColorAttributeName:color])
attributes: [NSAttributedStringKey.foregroundColor:color])
}
}
fileprivate var x:CGFloat {
if let leftView = leftView {
return leftView.frame.origin.x + leftView.bounds.size.width + paddingX
return leftView.frame.origin.x + leftView.bounds.size.width - paddingX
}
return paddingX
@@ -137,6 +161,10 @@ public class DTTextField: UITextField {
}
}
public override var textAlignment: NSTextAlignment{
didSet{ setNeedsLayout() }
}
public override var text: String?{
didSet{ self.textFieldTextChanged() }
}
@@ -149,7 +177,7 @@ public class DTTextField: UITextField {
return
}
attributedPlaceholder = NSAttributedString(string: placeholderFinal,
attributes: [NSForegroundColorAttributeName:color])
attributes: [NSAttributedStringKey.foregroundColor:color])
}
}
@@ -176,11 +204,10 @@ public class DTTextField: UITextField {
showErrorLabel = false
}
fileprivate func commonInit() {
dtLayer.cornerRadius = 4.5
dtLayer.borderWidth = 0.5
dtLayer.borderColor = borderColor.cgColor
dtborderStyle = .rounded
dtLayer.backgroundColor = UIColor.white.cgColor
floatPlaceholderColor = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0)
@@ -209,12 +236,52 @@ public class DTTextField: UITextField {
lblError.text = errorMessage
lblError.isHidden = false
let boundWithPadding = CGSize(width: bounds.width - (x * 2), height: bounds.height)
let errorLabelSize = lblError.sizeThatFits(boundWithPadding)
lblError.frame = CGRect(x: paddingX, y: 0, width: errorLabelSize.width, height: errorLabelSize.height)
let boundWithPadding = CGSize(width: bounds.width - (paddingX * 2), height: bounds.height)
lblError.frame = CGRect(x: paddingX, y: 0, width: boundWithPadding.width, height: boundWithPadding.height)
lblError.sizeToFit()
invalidateIntrinsicContentSize()
}
func setErrorLabelAlignment() {
var newFrame = lblError.frame
if textAlignment == .right {
newFrame.origin.x = bounds.width - paddingX - newFrame.size.width
}else if textAlignment == .left{
newFrame.origin.x = paddingX
}else if textAlignment == .center{
newFrame.origin.x = (bounds.width / 2.0) - (newFrame.size.width / 2.0)
}else if textAlignment == .natural{
if UIView.userInterfaceLayoutDirection(for: semanticContentAttribute) == .rightToLeft{
newFrame.origin.x = bounds.width - paddingX - newFrame.size.width
}
}
lblError.frame = newFrame
}
func setFloatLabelAlignment() {
var newFrame = lblFloatPlaceholder.frame
if textAlignment == .right {
newFrame.origin.x = bounds.width - paddingX - newFrame.size.width
}else if textAlignment == .left{
newFrame.origin.x = paddingX
}else if textAlignment == .center{
newFrame.origin.x = (bounds.width / 2.0) - (newFrame.size.width / 2.0)
}else if textAlignment == .natural{
if UIView.userInterfaceLayoutDirection(for: semanticContentAttribute) == .rightToLeft{
newFrame.origin.x = bounds.width - paddingX - newFrame.size.width
}
}
lblFloatPlaceholder.frame = newFrame
}
fileprivate func hideErrorMessage(){
lblError.text = ""
lblError.isHidden = true
@@ -271,13 +338,13 @@ public class DTTextField: UITextField {
}
fileprivate func insetRectForEmptyBounds(rect:CGRect) -> CGRect{
guard showErrorLabel else { return CGRect(x: x, y: 0, width: rect.width - paddingX, height: rect.height) }
let newX = x
guard showErrorLabel else { return CGRect(x: newX, y: 0, width: rect.width - newX - paddingX, height: rect.height) }
let topInset = (rect.size.height - lblError.bounds.size.height - paddingYErrorLabel - fontHeight) / 2.0
let textY = topInset - ((rect.height - fontHeight) / 2.0)
return CGRect(x: x, y: floor(textY), width: rect.size.width - paddingX, height: rect.size.height)
return CGRect(x: newX, y: floor(textY), width: rect.size.width - newX - paddingX, height: rect.size.height)
}
fileprivate func insetRectForBounds(rect:CGRect) -> CGRect {
@@ -298,8 +365,8 @@ public class DTTextField: UITextField {
var textY = topInset - textOriginalY
if textY < 0 && !showErrorLabel { textY = topInset }
return CGRect(x: x, y: ceil(textY), width: rect.size.width - paddingX, height: rect.height)
let newX = x
return CGRect(x: newX, y: ceil(textY), width: rect.size.width - newX - paddingX, height: rect.height)
}
}
}
@@ -314,8 +381,6 @@ public class DTTextField: UITextField {
let textFieldIntrinsicContentSize = super.intrinsicContentSize
lblError.sizeToFit()
if showErrorLabel {
lblFloatPlaceholder.sizeToFit()
return CGSize(width: textFieldIntrinsicContentSize.width,
@@ -383,6 +448,8 @@ public class DTTextField: UITextField {
width: floatingLabelSize.width,
height: floatingLabelSize.height)
setErrorLabelAlignment()
setFloatLabelAlignment()
lblFloatPlaceholder.textColor = isFirstResponder ? floatPlaceholderActiveColor : floatPlaceholderColor
switch floatingDisplayStatus {
@@ -398,4 +465,6 @@ public class DTTextField: UITextField {
}
}
}
}
+28 -4
View File
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
0EBDB911205BD7EA001E212E /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0EBDB90F205BD7EA001E212E /* Localizable.strings */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
@@ -27,6 +28,10 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
0EBDB903205BCB1C001E212E /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Main.strings; sourceTree = "<group>"; };
0EBDB904205BCB1C001E212E /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
0EBDB912205BD7EE001E212E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
0EBDB915205BD839001E212E /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Localizable.strings; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* DTTextField_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DTTextField_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -79,6 +84,7 @@
607FACD21AFB9204008FA782 /* Example for DTTextField */ = {
isa = PBXGroup;
children = (
0EBDB90F205BD7EA001E212E /* Localizable.strings */,
F20EFAF61ED7136A00DE8008 /* DTTextField.swift */,
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
@@ -166,6 +172,7 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = XDZ4VN9T5R;
LastSwiftMigration = 0820;
};
607FACE41AFB9204008FA782 = {
@@ -182,6 +189,7 @@
knownRegions = (
en,
Base,
ar,
);
mainGroup = 607FACC71AFB9204008FA782;
productRefGroup = 607FACD11AFB9204008FA782 /* Products */;
@@ -200,6 +208,7 @@
buildActionMask = 2147483647;
files = (
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
0EBDB911205BD7EA001E212E /* Localizable.strings in Resources */,
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */,
);
@@ -244,10 +253,20 @@
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
0EBDB90F205BD7EA001E212E /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
0EBDB912205BD7EE001E212E /* Base */,
0EBDB915205BD839001E212E /* ar */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
607FACD91AFB9204008FA782 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
607FACDA1AFB9204008FA782 /* Base */,
0EBDB903205BCB1C001E212E /* ar */,
);
name = Main.storyboard;
sourceTree = "<group>";
@@ -256,6 +275,7 @@
isa = PBXVariantGroup;
children = (
607FACDF1AFB9204008FA782 /* Base */,
0EBDB904205BCB1C001E212E /* ar */,
);
name = LaunchScreen.xib;
sourceTree = "<group>";
@@ -267,6 +287,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
@@ -314,6 +335,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
@@ -354,13 +376,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = XDZ4VN9T5R;
INFOPLIST_FILE = DTTextField/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.DTTextField-Example1";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
@@ -368,13 +391,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = XDZ4VN9T5R;
INFOPLIST_FILE = DTTextField/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.DTTextField-Example1";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
@@ -0,0 +1,9 @@
/*
Arabic.strings
DTTextField
Created by Dhaval Thanki on 16/03/18.
Copyright © 2018 CocoaPods. All rights reserved.
*/
+38 -37
View File
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Kzc-T6-rcN">
<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="Kzc-T6-rcN">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@@ -24,7 +25,7 @@
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="T5N-VG-n0n">
<rect key="frame" x="0.0" y="0.0" width="375" height="332"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="307"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="First Name" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="LZk-sC-XSt" customClass="DTTextField" customModule="DTTextField_Example" customModuleProvider="target">
<rect key="frame" x="16" y="50" width="343" height="30"/>
@@ -38,52 +39,52 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Email" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="6gk-3f-Yz6" customClass="DTTextField" customModule="DTTextField_Example" customModuleProvider="target">
<rect key="frame" x="16" y="126" width="343" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Password" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="63c-z6-Pat" customClass="DTTextField" customModule="DTTextField_Example" customModuleProvider="target">
<rect key="frame" x="16" y="164" width="343" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" secureTextEntry="YES"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Confirm Password" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="zBn-BA-f2Y" customClass="DTTextField" customModule="DTTextField_Example" customModuleProvider="target">
<rect key="frame" x="16" y="202" width="343" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" secureTextEntry="YES"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Vp4-XI-7k7">
<rect key="frame" x="158.5" y="267" width="57" height="30"/>
<rect key="frame" x="158.5" y="242" width="57" height="30"/>
<state key="normal" title="Register"/>
<connections>
<action selector="onBtnSubmitClicked:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="vbi-gx-VFd"/>
</connections>
</button>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Email" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="G8b-0H-NOp" customClass="DTTextField" customModule="DTTextField_Example" customModuleProvider="target">
<rect key="frame" x="16" y="126" width="343" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Password" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="vOV-P3-5my" customClass="DTTextField" customModule="DTTextField_Example" customModuleProvider="target">
<rect key="frame" x="16" y="164" width="343" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Confirm Password" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="oVW-xu-ETH" customClass="DTTextField" customModule="DTTextField_Example" customModuleProvider="target">
<rect key="frame" x="16" y="202" width="343" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="oVW-xu-ETH" firstAttribute="leading" secondItem="vOV-P3-5my" secondAttribute="leading" id="2Ox-na-6ZX"/>
<constraint firstAttribute="trailing" secondItem="LZk-sC-XSt" secondAttribute="trailing" constant="16" id="7xF-Yy-7dc"/>
<constraint firstItem="LZk-sC-XSt" firstAttribute="leading" secondItem="T5N-VG-n0n" secondAttribute="leading" constant="16" id="8fK-In-ELG"/>
<constraint firstItem="zBn-BA-f2Y" firstAttribute="trailing" secondItem="63c-z6-Pat" secondAttribute="trailing" id="BhC-IN-UKU"/>
<constraint firstItem="zBn-BA-f2Y" firstAttribute="top" secondItem="63c-z6-Pat" secondAttribute="bottom" constant="8" id="Cwc-4p-Bbi"/>
<constraint firstItem="6gk-3f-Yz6" firstAttribute="leading" secondItem="ZMK-KE-9Cc" secondAttribute="leading" id="E56-qn-ZL2"/>
<constraint firstItem="G8b-0H-NOp" firstAttribute="top" secondItem="ZMK-KE-9Cc" secondAttribute="bottom" constant="8" id="9MY-nz-wjQ"/>
<constraint firstItem="vOV-P3-5my" firstAttribute="trailing" secondItem="G8b-0H-NOp" secondAttribute="trailing" id="BZ6-is-x2y"/>
<constraint firstItem="Vp4-XI-7k7" firstAttribute="top" secondItem="oVW-xu-ETH" secondAttribute="bottom" constant="10" id="Czg-UB-G6G"/>
<constraint firstItem="oVW-xu-ETH" firstAttribute="trailing" secondItem="vOV-P3-5my" secondAttribute="trailing" id="FFZ-h7-nmL"/>
<constraint firstItem="vOV-P3-5my" firstAttribute="leading" secondItem="G8b-0H-NOp" secondAttribute="leading" id="FlG-Yh-6D8"/>
<constraint firstAttribute="bottom" secondItem="Vp4-XI-7k7" secondAttribute="bottom" constant="35" id="HWJ-ke-SwV"/>
<constraint firstItem="ZMK-KE-9Cc" firstAttribute="leading" secondItem="LZk-sC-XSt" secondAttribute="leading" id="Jzj-d1-Cuc"/>
<constraint firstItem="63c-z6-Pat" firstAttribute="leading" secondItem="6gk-3f-Yz6" secondAttribute="leading" id="OjR-tc-La6"/>
<constraint firstItem="G8b-0H-NOp" firstAttribute="leading" secondItem="ZMK-KE-9Cc" secondAttribute="leading" id="X9C-jl-FiE"/>
<constraint firstItem="ZMK-KE-9Cc" firstAttribute="top" secondItem="LZk-sC-XSt" secondAttribute="bottom" constant="8" id="XKP-xw-pz9"/>
<constraint firstItem="63c-z6-Pat" firstAttribute="trailing" secondItem="6gk-3f-Yz6" secondAttribute="trailing" id="YEb-NT-sFz"/>
<constraint firstItem="6gk-3f-Yz6" firstAttribute="top" secondItem="ZMK-KE-9Cc" secondAttribute="bottom" constant="8" id="Z08-RU-aXk"/>
<constraint firstItem="6gk-3f-Yz6" firstAttribute="trailing" secondItem="ZMK-KE-9Cc" secondAttribute="trailing" id="a2N-wr-VXy"/>
<constraint firstItem="63c-z6-Pat" firstAttribute="top" secondItem="6gk-3f-Yz6" secondAttribute="bottom" constant="8" id="aPM-Xo-bCc"/>
<constraint firstItem="oVW-xu-ETH" firstAttribute="top" secondItem="vOV-P3-5my" secondAttribute="bottom" constant="8" id="eEv-lG-Ktc"/>
<constraint firstItem="Vp4-XI-7k7" firstAttribute="centerX" secondItem="oVW-xu-ETH" secondAttribute="centerX" id="noc-qO-6TG"/>
<constraint firstItem="G8b-0H-NOp" firstAttribute="trailing" secondItem="ZMK-KE-9Cc" secondAttribute="trailing" id="onN-5k-UBd"/>
<constraint firstItem="LZk-sC-XSt" firstAttribute="top" secondItem="T5N-VG-n0n" secondAttribute="top" constant="50" id="pmI-vf-fOU"/>
<constraint firstItem="Vp4-XI-7k7" firstAttribute="centerX" secondItem="zBn-BA-f2Y" secondAttribute="centerX" id="qqR-IB-W1J"/>
<constraint firstItem="ZMK-KE-9Cc" firstAttribute="trailing" secondItem="LZk-sC-XSt" secondAttribute="trailing" id="tZs-73-KYu"/>
<constraint firstItem="zBn-BA-f2Y" firstAttribute="leading" secondItem="63c-z6-Pat" secondAttribute="leading" id="wde-fS-5eM"/>
<constraint firstItem="Vp4-XI-7k7" firstAttribute="top" secondItem="zBn-BA-f2Y" secondAttribute="bottom" constant="35" id="xHo-6Z-Xaa"/>
<constraint firstItem="vOV-P3-5my" firstAttribute="top" secondItem="G8b-0H-NOp" secondAttribute="bottom" constant="8" id="xmr-Ec-n2N"/>
</constraints>
</view>
</subviews>
@@ -108,11 +109,11 @@
<navigationItem key="navigationItem" id="W1x-bm-hbZ"/>
<connections>
<outlet property="scrollView" destination="3qx-l3-jfU" id="Wim-19-5FL"/>
<outlet property="txtConfirmPassword" destination="zBn-BA-f2Y" id="kBp-NH-lSI"/>
<outlet property="txtEmail" destination="6gk-3f-Yz6" id="0vh-rG-4OR"/>
<outlet property="txtConfirmPassword" destination="oVW-xu-ETH" id="tc3-xT-Cq0"/>
<outlet property="txtEmail" destination="G8b-0H-NOp" id="roZ-B7-YhX"/>
<outlet property="txtFirstName" destination="LZk-sC-XSt" id="gxg-Mj-Ljm"/>
<outlet property="txtLastName" destination="ZMK-KE-9Cc" id="bQS-O5-38P"/>
<outlet property="txtPassword" destination="63c-z6-Pat" id="gjV-fO-CFS"/>
<outlet property="txtPassword" destination="vOV-P3-5my" id="9Id-na-8eO"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
@@ -125,7 +126,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="Kzc-T6-rcN" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="rBs-ML-edK">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
+84 -16
View File
@@ -24,6 +24,12 @@ public class DTTextField: UITextField {
case defaults
}
public enum DTBorderStyle{
case none
case rounded
case sqare
}
fileprivate var lblFloatPlaceholder:UILabel = UILabel()
fileprivate var lblError:UILabel = UILabel()
@@ -37,6 +43,24 @@ public class DTTextField: UITextField {
public var floatingLabelShowAnimationDuration = 0.3
public var floatingDisplayStatus:FloatingDisplayStatus = .defaults
public var dtborderStyle:DTBorderStyle = .rounded{
didSet{
switch dtborderStyle {
case .none:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.0
case .rounded:
dtLayer.cornerRadius = 4.5
dtLayer.borderWidth = 0.5
dtLayer.borderColor = borderColor.cgColor
case .sqare:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.5
dtLayer.borderColor = borderColor.cgColor
}
}
}
public var errorMessage:String = ""{
didSet{ lblError.text = errorMessage }
}
@@ -72,14 +96,14 @@ public class DTTextField: UITextField {
didSet{
guard let color = placeholderColor else { return }
attributedPlaceholder = NSAttributedString(string: placeholderFinal,
attributes: [NSForegroundColorAttributeName:color])
attributes: [NSAttributedStringKey.foregroundColor:color])
}
}
fileprivate var x:CGFloat {
if let leftView = leftView {
return leftView.frame.origin.x + leftView.bounds.size.width + paddingX
return leftView.frame.origin.x + leftView.bounds.size.width - paddingX
}
return paddingX
@@ -137,6 +161,10 @@ public class DTTextField: UITextField {
}
}
public override var textAlignment: NSTextAlignment{
didSet{ setNeedsLayout() }
}
public override var text: String?{
didSet{ self.textFieldTextChanged() }
}
@@ -149,7 +177,7 @@ public class DTTextField: UITextField {
return
}
attributedPlaceholder = NSAttributedString(string: placeholderFinal,
attributes: [NSForegroundColorAttributeName:color])
attributes: [NSAttributedStringKey.foregroundColor:color])
}
}
@@ -176,11 +204,10 @@ public class DTTextField: UITextField {
showErrorLabel = false
}
fileprivate func commonInit() {
dtLayer.cornerRadius = 4.5
dtLayer.borderWidth = 0.5
dtLayer.borderColor = borderColor.cgColor
dtborderStyle = .rounded
dtLayer.backgroundColor = UIColor.white.cgColor
floatPlaceholderColor = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0)
@@ -209,12 +236,52 @@ public class DTTextField: UITextField {
lblError.text = errorMessage
lblError.isHidden = false
let boundWithPadding = CGSize(width: bounds.width - (x * 2), height: bounds.height)
let errorLabelSize = lblError.sizeThatFits(boundWithPadding)
lblError.frame = CGRect(x: paddingX, y: 0, width: errorLabelSize.width, height: errorLabelSize.height)
let boundWithPadding = CGSize(width: bounds.width - (paddingX * 2), height: bounds.height)
lblError.frame = CGRect(x: paddingX, y: 0, width: boundWithPadding.width, height: boundWithPadding.height)
lblError.sizeToFit()
invalidateIntrinsicContentSize()
}
func setErrorLabelAlignment() {
var newFrame = lblError.frame
if textAlignment == .right {
newFrame.origin.x = bounds.width - paddingX - newFrame.size.width
}else if textAlignment == .left{
newFrame.origin.x = paddingX
}else if textAlignment == .center{
newFrame.origin.x = (bounds.width / 2.0) - (newFrame.size.width / 2.0)
}else if textAlignment == .natural{
if UIView.userInterfaceLayoutDirection(for: semanticContentAttribute) == .rightToLeft{
newFrame.origin.x = bounds.width - paddingX - newFrame.size.width
}
}
lblError.frame = newFrame
}
func setFloatLabelAlignment() {
var newFrame = lblFloatPlaceholder.frame
if textAlignment == .right {
newFrame.origin.x = bounds.width - paddingX - newFrame.size.width
}else if textAlignment == .left{
newFrame.origin.x = paddingX
}else if textAlignment == .center{
newFrame.origin.x = (bounds.width / 2.0) - (newFrame.size.width / 2.0)
}else if textAlignment == .natural{
if UIView.userInterfaceLayoutDirection(for: semanticContentAttribute) == .rightToLeft{
newFrame.origin.x = bounds.width - paddingX - newFrame.size.width
}
}
lblFloatPlaceholder.frame = newFrame
}
fileprivate func hideErrorMessage(){
lblError.text = ""
lblError.isHidden = true
@@ -271,13 +338,13 @@ public class DTTextField: UITextField {
}
fileprivate func insetRectForEmptyBounds(rect:CGRect) -> CGRect{
guard showErrorLabel else { return CGRect(x: x, y: 0, width: rect.width - paddingX, height: rect.height) }
let newX = x
guard showErrorLabel else { return CGRect(x: newX, y: 0, width: rect.width - newX - paddingX, height: rect.height) }
let topInset = (rect.size.height - lblError.bounds.size.height - paddingYErrorLabel - fontHeight) / 2.0
let textY = topInset - ((rect.height - fontHeight) / 2.0)
return CGRect(x: x, y: floor(textY), width: rect.size.width - paddingX, height: rect.size.height)
return CGRect(x: newX, y: floor(textY), width: rect.size.width - newX - paddingX, height: rect.size.height)
}
fileprivate func insetRectForBounds(rect:CGRect) -> CGRect {
@@ -298,8 +365,8 @@ public class DTTextField: UITextField {
var textY = topInset - textOriginalY
if textY < 0 && !showErrorLabel { textY = topInset }
return CGRect(x: x, y: ceil(textY), width: rect.size.width - paddingX, height: rect.height)
let newX = x
return CGRect(x: newX, y: ceil(textY), width: rect.size.width - newX - paddingX, height: rect.height)
}
}
}
@@ -314,8 +381,6 @@ public class DTTextField: UITextField {
let textFieldIntrinsicContentSize = super.intrinsicContentSize
lblError.sizeToFit()
if showErrorLabel {
lblFloatPlaceholder.sizeToFit()
return CGSize(width: textFieldIntrinsicContentSize.width,
@@ -383,6 +448,8 @@ public class DTTextField: UITextField {
width: floatingLabelSize.width,
height: floatingLabelSize.height)
setErrorLabelAlignment()
setFloatLabelAlignment()
lblFloatPlaceholder.textColor = isFirstResponder ? floatPlaceholderActiveColor : floatPlaceholderColor
switch floatingDisplayStatus {
@@ -398,4 +465,5 @@ public class DTTextField: UITextField {
}
}
}
}
+15 -11
View File
@@ -17,20 +17,24 @@ class ViewController: UIViewController {
@IBOutlet weak var txtPassword: DTTextField!
@IBOutlet weak var txtConfirmPassword: DTTextField!
let firstNameMessage = "First name is required."
let lastNameMessage = "Last name is requried."
let emailMessage = "Email is required."
let passwordMessage = "Password is required."
let confirmPasswordMessage = "Confirm password is required."
let mismatchPasswordMessage = "Password and Confirm password are not matching."
let firstNameMessage = NSLocalizedString("First name is required.", comment: "")
let lastNameMessage = NSLocalizedString("Last name is required.", comment: "")
let emailMessage = NSLocalizedString("Email is required.", comment: "")
let passwordMessage = NSLocalizedString("Password is required.", comment: "")
let confirmPasswordMessage = NSLocalizedString("Confirm password is required.", comment: "")
let mismatchPasswordMessage = NSLocalizedString("Password and Confirm password are not matching.", comment: "")
override func viewDidLoad() {
super.viewDidLoad()
title = "Registration"
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
@@ -74,12 +78,12 @@ class ViewController: UIViewController {
// MARK: User Define Methods
extension ViewController{
func keyboardWillShow(notification:Notification) {
@objc func keyboardWillShow(notification:Notification) {
guard let keyboardHeight = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue else { return }
scrollView.contentInset = UIEdgeInsetsMake(0, 0, keyboardHeight.height, 0)
}
func keyboardWillHide(notification:Notification) {
@objc func keyboardWillHide(notification:Notification) {
scrollView.contentInset = .zero
}
@@ -99,7 +103,7 @@ extension ViewController{
txtEmail.showError(message: emailMessage)
return false
}
guard !txtPassword.text!.isEmptyStr else {
txtPassword.showError(message: passwordMessage)
return false
@@ -0,0 +1,6 @@
/* Class = "UILabel"; text = " Copyright (c) 2017 Dhaval Thanki. All rights reserved."; ObjectID = "8ie-xW-0ye"; */
"8ie-xW-0ye.text" = " Copyright (c) 2017 Dhaval Thanki. All rights reserved.";
/* Class = "UILabel"; text = "DTTextField"; ObjectID = "kId-c2-rCX"; */
"kId-c2-rCX.text" = "DTTextField";
@@ -0,0 +1,14 @@
/*
Arabic.strings
DTTextField
Created by Dhaval Thanki on 16/03/18.
Copyright © 2018 CocoaPods. All rights reserved.
*/
"First name is required." = "الإسم الأول مطلوب.";
"Last name is requried." = "الاسم الأخير مطلوب.";
"Email is required." = "البريد الالكتروني مطلوب.";
"Password is required." = "كلمة المرور مطلوبة.";
"Confirm password is required." = "تأكيد كلمة المرور مطلوب.";
"Password and Confirm password are not matching." = "كلمة المرور وتأكيد كلمة المرورغير متطابقين.";
+18
View File
@@ -0,0 +1,18 @@
/* Class = "UITextField"; placeholder = "Password"; ObjectID = "63c-z6-Pat"; */
"vOV-P3-5my.placeholder" = "كلمه السر";
/* Class = "UITextField"; placeholder = "Email"; ObjectID = "6gk-3f-Yz6"; */
"G8b-0H-NOp.placeholder" = "البريد الإلكتروني";
/* Class = "UITextField"; placeholder = "First Name"; ObjectID = "LZk-sC-XSt"; */
"LZk-sC-XSt.placeholder" = "الاسم الاول";
/* Class = "UIButton"; normalTitle = "Register"; ObjectID = "Vp4-XI-7k7"; */
"Vp4-XI-7k7.normalTitle" = "تسجيل";
/* Class = "UITextField"; placeholder = "Last Name"; ObjectID = "ZMK-KE-9Cc"; */
"ZMK-KE-9Cc.placeholder" = "الكنية";
/* Class = "UITextField"; placeholder = "Confirm Password"; ObjectID = "zBn-BA-f2Y"; */
"oVW-xu-ETH.placeholder" = "تأكيد كلمة المرور";
@@ -0,0 +1,9 @@
/*
Arabic.strings
DTTextField
Created by Dhaval Thanki on 16/03/18.
Copyright © 2018 CocoaPods. All rights reserved.
*/
+3 -3
View File
@@ -1,6 +1,6 @@
# DTTextField
[![Version](https://img.shields.io/badge/Pod-V0.2.5-green.svg)](https://github.com/iDhaval/DTTextField/releases/tag/0.2.4)
[![Version](https://img.shields.io/badge/Pod-V0.2.7-green.svg)](https://github.com/iDhaval/DTTextField/releases/tag/0.2.4)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/iDhaval/DTTextField/blob/master/LICENSE)
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/matteocrippa/awesome-swift)
[![Platform](https://img.shields.io/badge/Language-Swift_3.0-orange.svg)](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/)
@@ -20,8 +20,8 @@ Clone the repo and run the example project from the Example directory.
## Requirements
* Xcode 8.0
* Swift 3.0
* Xcode 8.0+
* Swift 3.0+
## Installation