Skip to content

Commit 105ff11

Browse files
author
Evgeniy Leychenko
committed
fixed typos
1 parent 84e5ad6 commit 105ff11

File tree

10 files changed

+146
-17
lines changed

10 files changed

+146
-17
lines changed

TextFieldEffects/TextFieldEffects/AkiraTextField.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import UIKit
1616
private let borderSize: (active: CGFloat, inactive: CGFloat) = (1, 2)
1717
private let borderLayer = CALayer()
1818
private let textFieldInsets = CGPoint(x: 6, y: 0)
19-
private let placeHolderInsets = CGPoint(x: 6, y: 0)
19+
private let placeholderInsets = CGPoint(x: 6, y: 0)
2020

2121
/**
2222
The color of the border.
@@ -32,7 +32,7 @@ import UIKit
3232
/**
3333
The color of the placeholder text.
3434

35-
This property applies a color to the complete placeholder string. The default value for this property is a black color.
35+
This property applies a color to the complete placeholder string. The default value for this property is a black color.
3636
*/
3737
@IBInspectable dynamic open var placeholderColor: UIColor = .black {
3838
didSet {
@@ -113,7 +113,7 @@ import UIKit
113113
}
114114

115115
private var placeholderHeight : CGFloat {
116-
return placeHolderInsets.y + placeholderFontFromFont(font!).lineHeight;
116+
return placeholderInsets.y + placeholderFontFromFont(font!).lineHeight
117117
}
118118

119119
private func rectForBounds(_ bounds: CGRect) -> CGRect {
@@ -124,7 +124,7 @@ import UIKit
124124

125125
open override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
126126
if isFirstResponder || text!.isNotEmpty {
127-
return CGRect(x: placeHolderInsets.x, y: placeHolderInsets.y, width: bounds.width, height: placeholderHeight)
127+
return CGRect(x: placeholderInsets.x, y: placeholderInsets.y, width: bounds.width, height: placeholderHeight)
128128
} else {
129129
return textRect(forBounds: bounds)
130130
}

TextFieldEffects/TextFieldEffects/HoshiTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import UIKit
7777
private let activeBorderLayer = CALayer()
7878
private var activePlaceholderPoint: CGPoint = CGPoint.zero
7979

80-
// MARK: - TextFieldsEffects
80+
// MARK: - TextFieldEffects
8181

8282
override open func drawViewsForRect(_ rect: CGRect) {
8383
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: rect.size.width, height: rect.size.height))

TextFieldEffects/TextFieldEffects/IsaoTextField.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import UIKit
6464
private let textFieldInsets = CGPoint(x: 6, y: 6)
6565
private let borderLayer = CALayer()
6666

67-
// MARK: - TextFieldsEffects
67+
// MARK: - TextFieldEffects
6868

6969
override open func drawViewsForRect(_ rect: CGRect) {
7070
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: rect.size.width, height: rect.size.height))
@@ -82,14 +82,14 @@ import UIKit
8282
override open func animateViewsForTextEntry() {
8383
updateBorder()
8484
if let activeColor = activeColor {
85-
performPlacerholderAnimationWithColor(activeColor)
85+
performPlaceholderAnimationWithColor(activeColor)
8686
}
8787
}
8888

8989
override open func animateViewsForTextDisplay() {
9090
updateBorder()
9191
if let inactiveColor = inactiveColor {
92-
performPlacerholderAnimationWithColor(inactiveColor)
92+
performPlaceholderAnimationWithColor(inactiveColor)
9393
}
9494
}
9595

@@ -143,7 +143,7 @@ import UIKit
143143
width: placeholderLabel.frame.size.width, height: placeholderLabel.frame.size.height)
144144
}
145145

146-
private func performPlacerholderAnimationWithColor(_ color: UIColor) {
146+
private func performPlaceholderAnimationWithColor(_ color: UIColor) {
147147

148148
let yOffset: CGFloat = 4
149149

TextFieldEffects/TextFieldEffects/JiroTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import UIKit
6464
private let textFieldInsets = CGPoint(x: 8, y: 12)
6565
private let borderLayer = CALayer()
6666

67-
// MARK: - TextFieldsEffects
67+
// MARK: - TextFieldEffects
6868

6969
override open func drawViewsForRect(_ rect: CGRect) {
7070
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: rect.size.width, height: rect.size.height))

TextFieldEffects/TextFieldEffects/KaedeTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import UIKit
6262
private let placeholderInsets = CGPoint(x: 10, y: 5)
6363
private let textFieldInsets = CGPoint(x: 10, y: 0)
6464

65-
// MARK: - TextFieldsEffects
65+
// MARK: - TextFieldEffects
6666

6767
override open func drawViewsForRect(_ rect: CGRect) {
6868
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: rect.size.width, height: rect.size.height))

TextFieldEffects/TextFieldEffects/MadokaTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import UIKit
6565
private let borderLayer = CAShapeLayer()
6666
private var backgroundLayerColor: UIColor?
6767

68-
// MARK: - TextFieldsEffects
68+
// MARK: - TextFieldEffects
6969

7070
override open func drawViewsForRect(_ rect: CGRect) {
7171
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: rect.size.width, height: rect.size.height))

TextFieldEffects/TextFieldEffects/MinoruTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import UIKit
6363
private let borderLayer = CALayer()
6464
private var backgroundLayerColor: UIColor?
6565

66-
// MARK: - TextFieldsEffects
66+
// MARK: - TextFieldEffects
6767

6868
override open func drawViewsForRect(_ rect: CGRect) {
6969
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: rect.size.width, height: rect.size.height))
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//
2+
// TextFieldEffects.swift
3+
// TextFieldEffects
4+
//
5+
// Created by Raúl Riera on 24/01/2015.
6+
// Copyright (c) 2015 Raul Riera. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension String {
12+
/**
13+
true if self contains characters.
14+
*/
15+
public var isNotEmpty: Bool {
16+
return !isEmpty
17+
}
18+
}
19+
20+
/**
21+
A TextFieldEffects object is a control that displays editable text and contains the boilerplates to setup unique animations for text entry and display. You typically use this class the same way you use UITextField.
22+
*/
23+
open class TextFieldEffects : UITextField {
24+
25+
/**
26+
The type of animation a TextFieldEffect can perform.
27+
28+
- TextEntry: animation that takes effect when the textfield has focus.
29+
- TextDisplay: animation that takes effect when the textfield loses focus.
30+
*/
31+
public enum AnimationType: Int {
32+
case textEntry
33+
case textDisplay
34+
}
35+
36+
/**
37+
Closure executed when an animation has been completed.
38+
*/
39+
public typealias AnimationCompletionHandler = (_ type: AnimationType)->()
40+
41+
/**
42+
UILabel that holds all the placeholder information
43+
*/
44+
open let placeholderLabel = UILabel()
45+
46+
/**
47+
Creates all the animations that are used to leave the textfield in the "entering text" state.
48+
*/
49+
open func animateViewsForTextEntry() {
50+
fatalError("\(#function) must be overridden")
51+
}
52+
53+
/**
54+
Creates all the animations that are used to leave the textfield in the "display input text" state.
55+
*/
56+
open func animateViewsForTextDisplay() {
57+
fatalError("\(#function) must be overridden")
58+
}
59+
60+
/**
61+
The animation completion handler is the best place to be notified when the text field animation has ended.
62+
*/
63+
open var animationCompletionHandler: AnimationCompletionHandler?
64+
65+
/**
66+
Draws the receiver’s image within the passed-in rectangle.
67+
68+
- parameter rect: The portion of the view’s bounds that needs to be updated.
69+
*/
70+
open func drawViewsForRect(_ rect: CGRect) {
71+
fatalError("\(#function) must be overridden")
72+
}
73+
74+
open func updateViewsForBoundsChange(_ bounds: CGRect) {
75+
fatalError("\(#function) must be overridden")
76+
}
77+
78+
// MARK: - Overrides
79+
80+
override open func draw(_ rect: CGRect) {
81+
drawViewsForRect(rect)
82+
}
83+
84+
override open func drawPlaceholder(in rect: CGRect) {
85+
// Don't draw any placeholders
86+
}
87+
88+
override open var text: String? {
89+
didSet {
90+
if let text = text, text.isNotEmpty {
91+
animateViewsForTextEntry()
92+
} else {
93+
animateViewsForTextDisplay()
94+
}
95+
}
96+
}
97+
98+
// MARK: - UITextField Observing
99+
100+
override open func willMove(toSuperview newSuperview: UIView!) {
101+
if newSuperview != nil {
102+
NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditing), name: NSNotification.Name.UITextFieldTextDidEndEditing, object: self)
103+
104+
NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditing), name: NSNotification.Name.UITextFieldTextDidBeginEditing, object: self)
105+
} else {
106+
NotificationCenter.default.removeObserver(self)
107+
}
108+
}
109+
110+
/**
111+
The textfield has started an editing session.
112+
*/
113+
open func textFieldDidBeginEditing() {
114+
animateViewsForTextEntry()
115+
}
116+
117+
/**
118+
The textfield has ended an editing session.
119+
*/
120+
open func textFieldDidEndEditing() {
121+
animateViewsForTextDisplay()
122+
}
123+
124+
// MARK: - Interface Builder
125+
126+
override open func prepareForInterfaceBuilder() {
127+
drawViewsForRect(frame)
128+
}
129+
}

TextFieldEffects/TextFieldEffects/YokoTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import UIKit
6565
private let placeholderInsets = CGPoint(x: 6, y: 6)
6666
private let textFieldInsets = CGPoint(x: 6, y: 6)
6767

68-
// MARK: - TextFieldsEffects
68+
// MARK: - TextFieldEffects
6969

7070
override open func drawViewsForRect(_ rect: CGRect) {
7171
updateForeground()

TextFieldEffects/TextFieldsDemo/ExampleTableViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class ExampleTableViewController : UITableViewController {
1717
Set this value to true if you want to see all the "firstName"
1818
textFields prepopulated with the name "Raul" (for testing purposes)
1919
*/
20-
let prefillTextField = false
20+
let prefillTextFields = false
2121

2222
override func viewDidLoad() {
2323
super.viewDidLoad()
2424

25-
guard prefillTextField == true else { return }
25+
guard prefillTextFields == true else { return }
2626

2727
_ = textFields.map { $0.text = "Raul" }
2828
}
29-
}
29+
}

0 commit comments

Comments
 (0)