Skip to content

Commit c4a42ec

Browse files
committed
Code refactoring
1 parent 409c1dd commit c4a42ec

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

TextFieldEffects/TextFieldEffects/MinoruTextField.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import UIKit
6666
}
6767

6868
private func updateBorder() {
69-
borderLayer.frame = rectForBorder()
69+
borderLayer.frame = rectForBorder(frame)
7070
borderLayer.backgroundColor = backgroundColor?.CGColor
7171
}
7272

@@ -86,10 +86,10 @@ import UIKit
8686
return smallerFont
8787
}
8888

89-
private func rectForBorder() -> CGRect {
90-
var newRect = CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height - 15)
89+
private func rectForBorder(bounds: CGRect) -> CGRect {
90+
var newRect = CGRect(x: 0, y: 0, width: bounds.size.width, height: bounds.size.height - font.lineHeight + textFieldInsets.y)
9191

92-
return CGRectInset(newRect, textFieldInsets.x, textFieldInsets.y)
92+
return newRect
9393
}
9494

9595
private func layoutPlaceholderInTextRect() {
@@ -141,14 +141,14 @@ import UIKit
141141
}
142142

143143
override func editingRectForBounds(bounds: CGRect) -> CGRect {
144-
let newBounds = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width, height: bounds.size.height - placeholderLabel.frame.size.height))
145-
return CGRectInset(newBounds, textFieldInsets.x * 2, 0)
144+
let newBounds = rectForBorder(bounds)
145+
return CGRectInset(newBounds, textFieldInsets.x, 0)
146146
}
147147

148148
override func textRectForBounds(bounds: CGRect) -> CGRect {
149-
let newBounds = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width, height: bounds.size.height - placeholderLabel.frame.size.height))
149+
let newBounds = rectForBorder(bounds)
150150

151-
return CGRectInset(newBounds, textFieldInsets.x * 2, 0)
151+
return CGRectInset(newBounds, textFieldInsets.x, 0)
152152
}
153153

154154
override func prepareForInterfaceBuilder() {

0 commit comments

Comments
 (0)