4 Commits

Author SHA1 Message Date
Dhaval Thanki bf8036ccf0 Following raised issue resolved
#12 Underlining mode of UI
#14 NSAttributedStringKey doesn't work
#15 Font Size of Floating Label
#17 Problem with foregroundColor
#18 The text is positioned above the top line using the dtlayer property. Using Xcode 10 and Swift 4.2
#19 This library not working in Xcode 10.1 & swift 4.2
2020-04-11 13:31:55 +05:30
Dhaval Thanki 1dfd86ba3b Update README.md 2018-03-16 17:44:46 +05:30
Dhaval Thanki cfaf5ea7ce Update README.md 2018-03-16 17:43:33 +05:30
Dhaval Thanki 0ff12c3e50 Update README.md 2018-03-16 17:34:25 +05:30
8 changed files with 163 additions and 79 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
Pod::Spec.new do |s|
s.name = 'DTTextField'
s.version = '0.3.0'
s.version = '0.4.0'
s.summary = 'DTTextField is UITextField library.'
s.description = <<-DESC
+60 -14
View File
@@ -28,6 +28,10 @@ public class DTTextField: UITextField {
case none
case rounded
case sqare
case top
case bottom
case left
case right
}
fileprivate var lblFloatPlaceholder:UILabel = UILabel()
@@ -36,27 +40,48 @@ public class DTTextField: UITextField {
fileprivate let paddingX:CGFloat = 5.0
fileprivate let paddingHeight:CGFloat = 10.0
fileprivate var borderLayer:CALayer = CALayer()
public var dtLayer:CALayer = CALayer()
public var floatPlaceholderColor:UIColor = UIColor.black
public var floatPlaceholderActiveColor:UIColor = UIColor.black
public var floatingLabelShowAnimationDuration = 0.3
public var floatingDisplayStatus:FloatingDisplayStatus = .defaults
public var borderWidth:CGFloat = 0.5{
didSet{
let borderStyle = dtborderStyle;
dtborderStyle = borderStyle
}
}
public var dtborderStyle:DTBorderStyle = .rounded{
didSet{
borderLayer.removeFromSuperlayer()
switch dtborderStyle {
case .none:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.0
case .rounded:
dtLayer.cornerRadius = 4.5
dtLayer.borderWidth = 0.5
dtLayer.borderWidth = borderWidth
dtLayer.borderColor = borderColor.cgColor
case .sqare:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.5
dtLayer.borderWidth = borderWidth
dtLayer.borderColor = borderColor.cgColor
case .bottom,.left,.right,.top:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.0
borderLayer.backgroundColor = borderColor.cgColor
if dtborderStyle == .bottom {
borderLayer.frame = CGRect(x: 0, y: dtLayer.bounds.size.height - borderWidth, width: dtLayer.bounds.size.width, height: borderWidth)
}else if dtborderStyle == .left{
borderLayer.frame = CGRect(x: 0, y: 0, width: borderWidth, height: dtLayer.bounds.size.height)
}else if dtborderStyle == .right{
borderLayer.frame = CGRect(x: dtLayer.bounds.size.width - borderWidth, y: 0, width: borderWidth, height: dtLayer.bounds.size.height)
}else{
borderLayer.frame = CGRect(x: 0, y: 0, width: dtLayer.bounds.size.width, height: borderWidth)
}
dtLayer.addSublayer(borderLayer)
}
}
}
@@ -69,11 +94,17 @@ public class DTTextField: UITextField {
public var hideErrorWhenEditing:Bool = true
public var errorFont = UIFont.systemFont(ofSize: 10.0){
didSet{ invalidateIntrinsicContentSize() }
didSet{
lblError.font = errorFont
invalidateIntrinsicContentSize()
}
}
public var floatPlaceholderFont = UIFont.systemFont(ofSize: 10.0){
didSet{ invalidateIntrinsicContentSize() }
didSet{
lblFloatPlaceholder.font = floatPlaceholderFont
invalidateIntrinsicContentSize()
}
}
public var paddingYFloatLabel:CGFloat = 3.0{
@@ -85,18 +116,32 @@ public class DTTextField: UITextField {
}
public var borderColor:UIColor = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0){
didSet{ dtLayer.borderColor = borderColor.cgColor }
didSet{
switch dtborderStyle {
case .none,.rounded,.sqare:
dtLayer.borderColor = borderColor.cgColor
case .bottom,.right,.top,.left:
borderLayer.backgroundColor = borderColor.cgColor
}
}
}
public var canShowBorder:Bool = true{
didSet{ dtLayer.isHidden = !canShowBorder }
didSet{
switch dtborderStyle {
case .none,.rounded,.sqare:
dtLayer.isHidden = !canShowBorder
case .bottom,.right,.top,.left:
borderLayer.isHidden = !canShowBorder
}
}
}
public var placeholderColor:UIColor?{
didSet{
guard let color = placeholderColor else { return }
attributedPlaceholder = NSAttributedString(string: placeholderFinal,
attributes: [NSAttributedStringKey.foregroundColor:color])
attributes: [NSAttributedString.Key.foregroundColor:color])
}
}
@@ -154,7 +199,7 @@ public class DTTextField: UITextField {
}
}
override public var borderStyle: UITextBorderStyle{
override public var borderStyle: UITextField.BorderStyle{
didSet{
guard borderStyle != oldValue else { return }
borderStyle = .none
@@ -177,7 +222,7 @@ public class DTTextField: UITextField {
return
}
attributedPlaceholder = NSAttributedString(string: placeholderFinal,
attributes: [NSAttributedStringKey.foregroundColor:color])
attributes: [NSAttributedString.Key.foregroundColor:color])
}
}
@@ -204,7 +249,7 @@ public class DTTextField: UITextField {
showErrorLabel = false
}
fileprivate func commonInit() {
dtborderStyle = .rounded
@@ -276,7 +321,7 @@ public class DTTextField: UITextField {
if UIView.userInterfaceLayoutDirection(for: semanticContentAttribute) == .rightToLeft{
newFrame.origin.x = bounds.width - paddingX - newFrame.size.width
}
}
lblFloatPlaceholder.frame = newFrame
@@ -433,6 +478,8 @@ public class DTTextField: UITextField {
y: bounds.origin.y,
width: bounds.width,
height: dtLayerHeight)
let borderStype = dtborderStyle
dtborderStyle = borderStype
CATransaction.commit()
if showErrorLabel {
@@ -465,6 +512,5 @@ public class DTTextField: UITextField {
}
}
}
}
}
@@ -187,6 +187,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
ar,
@@ -383,7 +384,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.DTTextField-Example1";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@@ -398,7 +399,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.DTTextField-Example1";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
+1 -1
View File
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
+18 -25
View File
@@ -1,11 +1,9 @@
<?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="Kzc-T6-rcN">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Kzc-T6-rcN">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15509"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@@ -22,65 +20,60 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3qx-l3-jfU">
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<rect key="frame" x="0.0" y="44" width="375" height="623"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="T5N-VG-n0n">
<rect key="frame" x="0.0" y="0.0" width="375" height="307"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="623"/>
<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"/>
<nil key="textColor"/>
<rect key="frame" x="16" y="50" width="343" height="34"/>
<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="Last Name" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="ZMK-KE-9Cc" customClass="DTTextField" customModule="DTTextField_Example" customModuleProvider="target">
<rect key="frame" x="16" y="88" width="343" height="30"/>
<nil key="textColor"/>
<rect key="frame" x="16" y="92" width="343" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</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="242" width="57" height="30"/>
<rect key="frame" x="159" y="262" 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"/>
<rect key="frame" x="16" y="134" width="343" height="34"/>
<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"/>
<rect key="frame" x="16" y="176" width="343" height="34"/>
<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"/>
<rect key="frame" x="16" y="218" width="343" height="34"/>
<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 firstItem="oVW-xu-ETH" firstAttribute="trailing" secondItem="vOV-P3-5my" secondAttribute="trailing" id="2Eh-Ef-dQi"/>
<constraint firstItem="oVW-xu-ETH" firstAttribute="leading" secondItem="vOV-P3-5my" secondAttribute="leading" id="2iy-n5-w9F"/>
<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="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 firstAttribute="bottom" relation="greaterThanOrEqual" 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="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="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="Vp4-XI-7k7" firstAttribute="centerX" secondItem="T5N-VG-n0n" secondAttribute="centerX" id="ikl-qL-tO7"/>
<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="ZMK-KE-9Cc" firstAttribute="trailing" secondItem="LZk-sC-XSt" secondAttribute="trailing" id="tZs-73-KYu"/>
@@ -118,7 +111,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="964" y="36.431784107946029"/>
<point key="canvasLocation" x="554" y="46"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="sQ1-e3-OIZ">
@@ -126,7 +119,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="20" width="375" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
@@ -136,7 +129,7 @@
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qlg-7C-Sy0" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="122" y="36"/>
<point key="canvasLocation" x="-194" y="47"/>
</scene>
</scenes>
</document>
+57 -10
View File
@@ -28,6 +28,10 @@ public class DTTextField: UITextField {
case none
case rounded
case sqare
case top
case bottom
case left
case right
}
fileprivate var lblFloatPlaceholder:UILabel = UILabel()
@@ -36,27 +40,48 @@ public class DTTextField: UITextField {
fileprivate let paddingX:CGFloat = 5.0
fileprivate let paddingHeight:CGFloat = 10.0
fileprivate var borderLayer:CALayer = CALayer()
public var dtLayer:CALayer = CALayer()
public var floatPlaceholderColor:UIColor = UIColor.black
public var floatPlaceholderActiveColor:UIColor = UIColor.black
public var floatingLabelShowAnimationDuration = 0.3
public var floatingDisplayStatus:FloatingDisplayStatus = .defaults
public var borderWidth:CGFloat = 0.5{
didSet{
let borderStyle = dtborderStyle;
dtborderStyle = borderStyle
}
}
public var dtborderStyle:DTBorderStyle = .rounded{
didSet{
borderLayer.removeFromSuperlayer()
switch dtborderStyle {
case .none:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.0
case .rounded:
dtLayer.cornerRadius = 4.5
dtLayer.borderWidth = 0.5
dtLayer.borderWidth = borderWidth
dtLayer.borderColor = borderColor.cgColor
case .sqare:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.5
dtLayer.borderWidth = borderWidth
dtLayer.borderColor = borderColor.cgColor
case .bottom,.left,.right,.top:
dtLayer.cornerRadius = 0.0
dtLayer.borderWidth = 0.0
borderLayer.backgroundColor = borderColor.cgColor
if dtborderStyle == .bottom {
borderLayer.frame = CGRect(x: 0, y: dtLayer.bounds.size.height - borderWidth, width: dtLayer.bounds.size.width, height: borderWidth)
}else if dtborderStyle == .left{
borderLayer.frame = CGRect(x: 0, y: 0, width: borderWidth, height: dtLayer.bounds.size.height)
}else if dtborderStyle == .right{
borderLayer.frame = CGRect(x: dtLayer.bounds.size.width - borderWidth, y: 0, width: borderWidth, height: dtLayer.bounds.size.height)
}else{
borderLayer.frame = CGRect(x: 0, y: 0, width: dtLayer.bounds.size.width, height: borderWidth)
}
dtLayer.addSublayer(borderLayer)
}
}
}
@@ -69,11 +94,17 @@ public class DTTextField: UITextField {
public var hideErrorWhenEditing:Bool = true
public var errorFont = UIFont.systemFont(ofSize: 10.0){
didSet{ invalidateIntrinsicContentSize() }
didSet{
lblError.font = errorFont
invalidateIntrinsicContentSize()
}
}
public var floatPlaceholderFont = UIFont.systemFont(ofSize: 10.0){
didSet{ invalidateIntrinsicContentSize() }
didSet{
lblFloatPlaceholder.font = floatPlaceholderFont
invalidateIntrinsicContentSize()
}
}
public var paddingYFloatLabel:CGFloat = 3.0{
@@ -85,18 +116,32 @@ public class DTTextField: UITextField {
}
public var borderColor:UIColor = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0){
didSet{ dtLayer.borderColor = borderColor.cgColor }
didSet{
switch dtborderStyle {
case .none,.rounded,.sqare:
dtLayer.borderColor = borderColor.cgColor
case .bottom,.right,.top,.left:
borderLayer.backgroundColor = borderColor.cgColor
}
}
}
public var canShowBorder:Bool = true{
didSet{ dtLayer.isHidden = !canShowBorder }
didSet{
switch dtborderStyle {
case .none,.rounded,.sqare:
dtLayer.isHidden = !canShowBorder
case .bottom,.right,.top,.left:
borderLayer.isHidden = !canShowBorder
}
}
}
public var placeholderColor:UIColor?{
didSet{
guard let color = placeholderColor else { return }
attributedPlaceholder = NSAttributedString(string: placeholderFinal,
attributes: [NSAttributedStringKey.foregroundColor:color])
attributes: [NSAttributedString.Key.foregroundColor:color])
}
}
@@ -154,7 +199,7 @@ public class DTTextField: UITextField {
}
}
override public var borderStyle: UITextBorderStyle{
override public var borderStyle: UITextField.BorderStyle{
didSet{
guard borderStyle != oldValue else { return }
borderStyle = .none
@@ -177,7 +222,7 @@ public class DTTextField: UITextField {
return
}
attributedPlaceholder = NSAttributedString(string: placeholderFinal,
attributes: [NSAttributedStringKey.foregroundColor:color])
attributes: [NSAttributedString.Key.foregroundColor:color])
}
}
@@ -433,6 +478,8 @@ public class DTTextField: UITextField {
y: bounds.origin.y,
width: bounds.width,
height: dtLayerHeight)
let borderStype = dtborderStyle
dtborderStyle = borderStype
CATransaction.commit()
if showErrorLabel {
+15 -20
View File
@@ -29,23 +29,18 @@ class ViewController: UIViewController {
// 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)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: .UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
}
override func didReceiveMemoryWarning() {
@@ -59,28 +54,28 @@ class ViewController: UIViewController {
let alert = UIAlertController(title: "Congratulations", message: "Your registration is successful!!!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (cancel) in
DispatchQueue.main.async {
self.txtFirstName.text = ""
self.txtLastName.text = ""
self.txtEmail.text = ""
self.txtConfirmPassword.text = ""
self.txtPassword.text = ""
}
DispatchQueue.main.async { self.clearForm() }
}))
present(alert, animated: true, completion: nil)
}
func clearForm() {
self.txtFirstName.text = ""
self.txtLastName.text = ""
self.txtEmail.text = ""
self.txtConfirmPassword.text = ""
self.txtPassword.text = ""
}
}
// MARK: User Define Methods
extension ViewController{
@objc func keyboardWillShow(notification:Notification) {
guard let keyboardHeight = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue else { return }
scrollView.contentInset = UIEdgeInsetsMake(0, 0, keyboardHeight.height, 0)
guard let keyboardHeight = (notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue else { return }
scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardHeight.height, right: 0)
}
@objc func keyboardWillHide(notification:Notification) {
+8 -6
View File
@@ -1,10 +1,10 @@
# DTTextField
[![Version](https://img.shields.io/badge/Pod-V0.2.7-green.svg)](https://github.com/iDhaval/DTTextField/releases/tag/0.2.4)
[![Version](https://img.shields.io/badge/Pod-V0.3.0-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/)
![Xcode](https://img.shields.io/badge/Xcode-8.0-blue.svg)
[![Platform](https://img.shields.io/badge/Language-Swift_4.0-orange.svg)](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/)
![Xcode](https://img.shields.io/badge/Xcode-9.0-blue.svg)
![Demo](https://github.com/iDhaval/DTTextField/blob/master/DTTextField.gif?raw=true)
@@ -20,8 +20,8 @@ Clone the repo and run the example project from the Example directory.
## Requirements
* Xcode 8.0+
* Swift 3.0+
* Xcode 11.0+
* Swift 5.0+
## Installation
@@ -54,13 +54,15 @@ pod 'DTTextField'
| hideErrorWhenEditing | Bool | hide error label when typing |
| floatingDisplayStatus | enum | maintain display status always, never, defaults |
### Important Properties
| Property name | Type | Remark |
| ------------- |------------- | ----- |
| dtLayer | CALayer | If you want to formate DTTextField than use dtLayer property instead of layer |
| dtLayer | CALayer | If you want to formate DTTextField than use dtLayer property instead of layer (e.g. background color) |
| borderColor | UIColor | Change border color of DTTextField |
| canShowBorder | Bool | Toggle border of DTTextField |
| dtborderStyle | enum | none, rounded , sqare |
## Methods