Skip to content

Commit 7f95379

Browse files
committed
Support for Swift 3.0-b1
1 parent acc5602 commit 7f95379

File tree

13 files changed

+341
-352
lines changed

13 files changed

+341
-352
lines changed

TextFieldEffects/TextFieldEffects.xcodeproj/project.pbxproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
11E69DA71B27B1A90025D54E /* AkiraTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11E69DA61B27B1A90025D54E /* AkiraTextField.swift */; };
1111
4C42C7711AB20C97009BE2A0 /* TextFieldEffects.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4CB3B6CE1AA8DEA7000AFA56 /* TextFieldEffects.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
12-
4C8036EB1B90A88E00218FAE /* ExampleTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8036EA1B90A88E00218FAE /* ExampleTableViewController.swift */; settings = {ASSET_TAGS = (); }; };
12+
4C8036EB1B90A88E00218FAE /* ExampleTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8036EA1B90A88E00218FAE /* ExampleTableViewController.swift */; };
1313
4CB3B6D31AA8DEA7000AFA56 /* TextFieldEffects.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CB3B6D21AA8DEA7000AFA56 /* TextFieldEffects.h */; settings = {ATTRIBUTES = (Public, ); }; };
1414
4CB3B6EF1AA8DEC3000AFA56 /* HoshiTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB3B6E71AA8DEC3000AFA56 /* HoshiTextField.swift */; };
1515
4CB3B6F01AA8DEC3000AFA56 /* IsaoTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB3B6E81AA8DEC3000AFA56 /* IsaoTextField.swift */; };
@@ -24,7 +24,7 @@
2424
4CBF76771A71AF7700073B6A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4CBF76751A71AF7700073B6A /* Main.storyboard */; };
2525
4CBF76791A71AF7700073B6A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4CBF76781A71AF7700073B6A /* Images.xcassets */; };
2626
4CBF767C1A71AF7700073B6A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CBF767A1A71AF7700073B6A /* LaunchScreen.xib */; };
27-
DF983ABB1BBD1F4100BCC4C7 /* YoshikoTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF983ABA1BBD1F4100BCC4C7 /* YoshikoTextField.swift */; settings = {ASSET_TAGS = (); }; };
27+
DF983ABB1BBD1F4100BCC4C7 /* YoshikoTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF983ABA1BBD1F4100BCC4C7 /* YoshikoTextField.swift */; };
2828
/* End PBXBuildFile section */
2929

3030
/* Begin PBXContainerItemProxy section */
@@ -222,9 +222,11 @@
222222
TargetAttributes = {
223223
4CB3B6CD1AA8DEA7000AFA56 = {
224224
CreatedOnToolsVersion = 6.2;
225+
LastSwiftMigration = 0800;
225226
};
226227
4CBF766C1A71AF7700073B6A = {
227228
CreatedOnToolsVersion = 6.1.1;
229+
LastSwiftMigration = 0800;
228230
};
229231
};
230232
};
@@ -343,6 +345,7 @@
343345
PRODUCT_NAME = "$(TARGET_NAME)";
344346
SKIP_INSTALL = YES;
345347
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
348+
SWIFT_VERSION = 3.0;
346349
};
347350
name = Debug;
348351
};
@@ -361,6 +364,7 @@
361364
PRODUCT_BUNDLE_IDENTIFIER = "com.raulriera.$(PRODUCT_NAME:rfc1034identifier)";
362365
PRODUCT_NAME = "$(TARGET_NAME)";
363366
SKIP_INSTALL = YES;
367+
SWIFT_VERSION = 3.0;
364368
};
365369
name = Release;
366370
};
@@ -463,6 +467,7 @@
463467
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
464468
PRODUCT_BUNDLE_IDENTIFIER = "com.raulriera.$(PRODUCT_NAME:rfc1034identifier)";
465469
PRODUCT_NAME = "$(TARGET_NAME)";
470+
SWIFT_VERSION = 3.0;
466471
};
467472
name = Debug;
468473
};
@@ -475,6 +480,7 @@
475480
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
476481
PRODUCT_BUNDLE_IDENTIFIER = "com.raulriera.$(PRODUCT_NAME:rfc1034identifier)";
477482
PRODUCT_NAME = "$(TARGET_NAME)";
483+
SWIFT_VERSION = 3.0;
478484
};
479485
name = Release;
480486
};

TextFieldEffects/TextFieldEffects/AkiraTextField.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import UIKit
3434

3535
This property applies a color to the complete placeholder string. The default value for this property is a black color.
3636
*/
37-
@IBInspectable dynamic public var placeholderColor: UIColor = .blackColor() {
37+
@IBInspectable dynamic public var placeholderColor: UIColor = .black() {
3838
didSet {
3939
updatePlaceholder()
4040
}
@@ -65,7 +65,7 @@ import UIKit
6565

6666
// MARK: TextFieldEffects
6767

68-
override public func drawViewsForRect(rect: CGRect) {
68+
override public func drawViewsForRect(_ rect: CGRect) {
6969
updateBorder()
7070
updatePlaceholder()
7171

@@ -74,27 +74,27 @@ import UIKit
7474
}
7575

7676
override public func animateViewsForTextEntry() {
77-
UIView.animateWithDuration(0.3, animations: {
77+
UIView.animate(withDuration: 0.3, animations: {
7878
self.updateBorder()
7979
self.updatePlaceholder()
8080
}, completion: { _ in
81-
self.animationCompletionHandler?(type: .TextEntry)
81+
self.animationCompletionHandler?(type: .textEntry)
8282
})
8383
}
8484

8585
override public func animateViewsForTextDisplay() {
86-
UIView.animateWithDuration(0.3, animations: {
86+
UIView.animate(withDuration: 0.3, animations: {
8787
self.updateBorder()
8888
self.updatePlaceholder()
8989
}, completion: { _ in
90-
self.animationCompletionHandler?(type: .TextDisplay)
90+
self.animationCompletionHandler?(type: .textDisplay)
9191
})
9292
}
9393

9494
// MARK: Private
9595

9696
private func updatePlaceholder() {
97-
placeholderLabel.frame = placeholderRectForBounds(bounds)
97+
placeholderLabel.frame = placeholderRect(forBounds: bounds)
9898
placeholderLabel.text = placeholder
9999
placeholderLabel.font = placeholderFontFromFont(font!)
100100
placeholderLabel.textColor = placeholderColor
@@ -104,10 +104,10 @@ import UIKit
104104
private func updateBorder() {
105105
borderLayer.frame = rectForBounds(bounds)
106106
borderLayer.borderWidth = (isFirstResponder() || text!.isNotEmpty) ? borderSize.active : borderSize.inactive
107-
borderLayer.borderColor = borderColor?.CGColor
107+
borderLayer.borderColor = borderColor?.cgColor
108108
}
109109

110-
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
110+
private func placeholderFontFromFont(_ font: UIFont) -> UIFont! {
111111
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
112112
return smallerFont
113113
}
@@ -116,26 +116,26 @@ import UIKit
116116
return placeHolderInsets.y + placeholderFontFromFont(font!).lineHeight;
117117
}
118118

119-
private func rectForBounds(bounds: CGRect) -> CGRect {
119+
private func rectForBounds(_ bounds: CGRect) -> CGRect {
120120
return CGRect(x: bounds.origin.x, y: bounds.origin.y + placeholderHeight, width: bounds.size.width, height: bounds.size.height - placeholderHeight)
121121
}
122122

123123
// MARK: - Overrides
124124

125-
public override func placeholderRectForBounds(bounds: CGRect) -> CGRect {
125+
public override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
126126
if isFirstResponder() || text!.isNotEmpty {
127-
return CGRectMake(placeHolderInsets.x, placeHolderInsets.y, bounds.width, placeholderHeight)
127+
return CGRect(x: placeHolderInsets.x, y: placeHolderInsets.y, width: bounds.width, height: placeholderHeight)
128128
} else {
129-
return textRectForBounds(bounds)
129+
return textRect(forBounds: bounds)
130130
}
131131
}
132132

133-
public override func editingRectForBounds(bounds: CGRect) -> CGRect {
134-
return textRectForBounds(bounds)
133+
public override func editingRect(forBounds bounds: CGRect) -> CGRect {
134+
return textRect(forBounds: bounds)
135135
}
136136

137-
override public func textRectForBounds(bounds: CGRect) -> CGRect {
138-
return CGRectOffset(bounds, textFieldInsets.x, textFieldInsets.y + placeholderHeight/2)
137+
override public func textRect(forBounds bounds: CGRect) -> CGRect {
138+
return bounds.offsetBy(dx: textFieldInsets.x, dy: textFieldInsets.y + placeholderHeight/2)
139139
}
140140
}
141141

TextFieldEffects/TextFieldEffects/HoshiTextField.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import UIKit
4040

4141
This property applies a color to the complete placeholder string. The default value for this property is a black color.
4242
*/
43-
@IBInspectable dynamic public var placeholderColor: UIColor = .blackColor() {
43+
@IBInspectable dynamic public var placeholderColor: UIColor = .black() {
4444
didSet {
4545
updatePlaceholder()
4646
}
@@ -75,14 +75,14 @@ import UIKit
7575
private let textFieldInsets = CGPoint(x: 0, y: 12)
7676
private let inactiveBorderLayer = CALayer()
7777
private let activeBorderLayer = CALayer()
78-
private var activePlaceholderPoint: CGPoint = CGPointZero
78+
private var activePlaceholderPoint: CGPoint = CGPoint.zero
7979

8080
// MARK: - TextFieldsEffects
8181

82-
override public func drawViewsForRect(rect: CGRect) {
83-
let frame = CGRect(origin: CGPointZero, size: CGSize(width: rect.size.width, height: rect.size.height))
82+
override public func drawViewsForRect(_ rect: CGRect) {
83+
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: rect.size.width, height: rect.size.height))
8484

85-
placeholderLabel.frame = CGRectInset(frame, placeholderInsets.x, placeholderInsets.y)
85+
placeholderLabel.frame = frame.insetBy(dx: placeholderInsets.x, dy: placeholderInsets.y)
8686
placeholderLabel.font = placeholderFontFromFont(font!)
8787

8888
updateBorder()
@@ -95,18 +95,18 @@ import UIKit
9595

9696
override public func animateViewsForTextEntry() {
9797
if text!.isEmpty {
98-
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1.0, options: .BeginFromCurrentState, animations: ({
98+
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1.0, options: .beginFromCurrentState, animations: ({
9999
self.placeholderLabel.frame.origin = CGPoint(x: 10, y: self.placeholderLabel.frame.origin.y)
100100
self.placeholderLabel.alpha = 0
101101
}), completion: { _ in
102-
self.animationCompletionHandler?(type: .TextEntry)
102+
self.animationCompletionHandler?(type: .textEntry)
103103
})
104104
}
105105

106106
layoutPlaceholderInTextRect()
107107
placeholderLabel.frame.origin = activePlaceholderPoint
108108

109-
UIView.animateWithDuration(0.2, animations: {
109+
UIView.animate(withDuration: 0.2, animations: {
110110
self.placeholderLabel.alpha = 0.5
111111
})
112112

@@ -115,25 +115,25 @@ import UIKit
115115

116116
override public func animateViewsForTextDisplay() {
117117
if text!.isEmpty {
118-
UIView.animateWithDuration(0.35, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: UIViewAnimationOptions.BeginFromCurrentState, animations: ({
118+
UIView.animate(withDuration: 0.35, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 2.0, options: UIViewAnimationOptions.beginFromCurrentState, animations: ({
119119
self.layoutPlaceholderInTextRect()
120120
self.placeholderLabel.alpha = 1
121121
}), completion: { _ in
122-
self.animationCompletionHandler?(type: .TextDisplay)
122+
self.animationCompletionHandler?(type: .textDisplay)
123123
})
124124

125-
self.activeBorderLayer.frame = self.rectForBorder(self.borderThickness.active, isFilled: false)
125+
activeBorderLayer.frame = self.rectForBorder(self.borderThickness.active, isFilled: false)
126126
}
127127
}
128128

129129
// MARK: - Private
130130

131131
private func updateBorder() {
132132
inactiveBorderLayer.frame = rectForBorder(borderThickness.inactive, isFilled: true)
133-
inactiveBorderLayer.backgroundColor = borderInactiveColor?.CGColor
133+
inactiveBorderLayer.backgroundColor = borderInactiveColor?.cgColor
134134

135135
activeBorderLayer.frame = rectForBorder(borderThickness.active, isFilled: false)
136-
activeBorderLayer.backgroundColor = borderActiveColor?.CGColor
136+
activeBorderLayer.backgroundColor = borderActiveColor?.cgColor
137137
}
138138

139139
private func updatePlaceholder() {
@@ -147,26 +147,26 @@ import UIKit
147147
}
148148
}
149149

150-
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
150+
private func placeholderFontFromFont(_ font: UIFont) -> UIFont! {
151151
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
152152
return smallerFont
153153
}
154154

155-
private func rectForBorder(thickness: CGFloat, isFilled: Bool) -> CGRect {
155+
private func rectForBorder(_ thickness: CGFloat, isFilled: Bool) -> CGRect {
156156
if isFilled {
157-
return CGRect(origin: CGPoint(x: 0, y: CGRectGetHeight(frame)-thickness), size: CGSize(width: CGRectGetWidth(frame), height: thickness))
157+
return CGRect(origin: CGPoint(x: 0, y: frame.height-thickness), size: CGSize(width: frame.width, height: thickness))
158158
} else {
159-
return CGRect(origin: CGPoint(x: 0, y: CGRectGetHeight(frame)-thickness), size: CGSize(width: 0, height: thickness))
159+
return CGRect(origin: CGPoint(x: 0, y: frame.height-thickness), size: CGSize(width: 0, height: thickness))
160160
}
161161
}
162162

163163
private func layoutPlaceholderInTextRect() {
164-
let textRect = textRectForBounds(bounds)
164+
let textRect = self.textRect(forBounds: bounds)
165165
var originX = textRect.origin.x
166166
switch self.textAlignment {
167-
case .Center:
167+
case .center:
168168
originX += textRect.size.width/2 - placeholderLabel.bounds.width/2
169-
case .Right:
169+
case .right:
170170
originX += textRect.size.width - placeholderLabel.bounds.width
171171
default:
172172
break
@@ -179,12 +179,12 @@ import UIKit
179179

180180
// MARK: - Overrides
181181

182-
override public func editingRectForBounds(bounds: CGRect) -> CGRect {
183-
return CGRectOffset(bounds, textFieldInsets.x, textFieldInsets.y)
182+
override public func editingRect(forBounds bounds: CGRect) -> CGRect {
183+
return bounds.offsetBy(dx: textFieldInsets.x, dy: textFieldInsets.y)
184184
}
185185

186-
override public func textRectForBounds(bounds: CGRect) -> CGRect {
187-
return CGRectOffset(bounds, textFieldInsets.x, textFieldInsets.y)
186+
override public func textRect(forBounds bounds: CGRect) -> CGRect {
187+
return bounds.offsetBy(dx: textFieldInsets.x, dy: textFieldInsets.y)
188188
}
189189

190-
}
190+
}

TextFieldEffects/TextFieldEffects/IsaoTextField.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ import UIKit
6666

6767
// MARK: - TextFieldsEffects
6868

69-
override public func drawViewsForRect(rect: CGRect) {
70-
let frame = CGRect(origin: CGPointZero, size: CGSize(width: rect.size.width, height: rect.size.height))
69+
override public func drawViewsForRect(_ rect: CGRect) {
70+
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: rect.size.width, height: rect.size.height))
7171

72-
placeholderLabel.frame = CGRectInset(frame, placeholderInsets.x, placeholderInsets.y)
72+
placeholderLabel.frame = frame.insetBy(dx: placeholderInsets.x, dy: placeholderInsets.y)
7373
placeholderLabel.font = placeholderFontFromFont(font!)
7474

7575
updateBorder()
@@ -97,7 +97,7 @@ import UIKit
9797

9898
private func updateBorder() {
9999
borderLayer.frame = rectForBorder(frame)
100-
borderLayer.backgroundColor = isFirstResponder() ? activeColor?.CGColor : inactiveColor?.CGColor
100+
borderLayer.backgroundColor = isFirstResponder() ? activeColor?.cgColor : inactiveColor?.cgColor
101101
}
102102

103103
private func updatePlaceholder() {
@@ -111,12 +111,12 @@ import UIKit
111111
}
112112
}
113113

114-
private func placeholderFontFromFont(font: UIFont) -> UIFont! {
114+
private func placeholderFontFromFont(_ font: UIFont) -> UIFont! {
115115
let smallerFont = UIFont(name: font.fontName, size: font.pointSize * placeholderFontScale)
116116
return smallerFont
117117
}
118118

119-
private func rectForBorder(bounds: CGRect) -> CGRect {
119+
private func rectForBorder(_ bounds: CGRect) -> CGRect {
120120
var newRect:CGRect
121121

122122
if isFirstResponder() {
@@ -129,12 +129,12 @@ import UIKit
129129
}
130130

131131
private func layoutPlaceholderInTextRect() {
132-
let textRect = textRectForBounds(bounds)
132+
let textRect = self.textRect(forBounds: bounds)
133133
var originX = textRect.origin.x
134134
switch textAlignment {
135-
case .Center:
135+
case .center:
136136
originX += textRect.size.width/2 - placeholderLabel.bounds.width/2
137-
case .Right:
137+
case .right:
138138
originX += textRect.size.width - placeholderLabel.bounds.width
139139
default:
140140
break
@@ -143,38 +143,38 @@ import UIKit
143143
width: placeholderLabel.frame.size.width, height: placeholderLabel.frame.size.height)
144144
}
145145

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

148148
let yOffset: CGFloat = 4
149149

150-
UIView.animateWithDuration(0.15, animations: {
151-
self.placeholderLabel.transform = CGAffineTransformMakeTranslation(0, -yOffset)
150+
UIView.animate(withDuration: 0.15, animations: {
151+
self.placeholderLabel.transform = CGAffineTransform(translationX: 0, y: -yOffset)
152152
self.placeholderLabel.alpha = 0
153153
}) { _ in
154-
self.placeholderLabel.transform = CGAffineTransformIdentity
155-
self.placeholderLabel.transform = CGAffineTransformMakeTranslation(0, yOffset)
154+
self.placeholderLabel.transform = CGAffineTransform.identity
155+
self.placeholderLabel.transform = CGAffineTransform(translationX: 0, y: yOffset)
156156

157-
UIView.animateWithDuration(0.15, animations: {
157+
UIView.animate(withDuration: 0.15, animations: {
158158
self.placeholderLabel.textColor = color
159-
self.placeholderLabel.transform = CGAffineTransformIdentity
159+
self.placeholderLabel.transform = CGAffineTransform.identity
160160
self.placeholderLabel.alpha = 1
161161
}) { _ in
162-
self.animationCompletionHandler?(type: self.isFirstResponder() ? .TextEntry : .TextDisplay)
162+
self.animationCompletionHandler?(type: self.isFirstResponder() ? .textEntry : .textDisplay)
163163
}
164164
}
165165
}
166166

167167
// MARK: - Overrides
168168

169-
override public func editingRectForBounds(bounds: CGRect) -> CGRect {
169+
override public func editingRect(forBounds bounds: CGRect) -> CGRect {
170170
let newBounds = CGRect(x: 0, y: 0, width: bounds.size.width, height: bounds.size.height - font!.lineHeight + textFieldInsets.y)
171-
return CGRectInset(newBounds, textFieldInsets.x, 0)
171+
return newBounds.insetBy(dx: textFieldInsets.x, dy: 0)
172172
}
173173

174-
override public func textRectForBounds(bounds: CGRect) -> CGRect {
174+
override public func textRect(forBounds bounds: CGRect) -> CGRect {
175175
let newBounds = CGRect(x: 0, y: 0, width: bounds.size.width, height: bounds.size.height - font!.lineHeight + textFieldInsets.y)
176176

177-
return CGRectInset(newBounds, textFieldInsets.x, 0)
177+
return newBounds.insetBy(dx: textFieldInsets.x, dy: 0)
178178
}
179179

180180
}

0 commit comments

Comments
 (0)