Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This pull-request contains improvements #306

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
NSRange(location: 0, length: floatingLabelTextField.placeholder!.count)
#else
var fullRange =
NSRange(location: 0, length: floatingLabelTextField.placeholder!.characters.count)
NSRange(location: 0, length: floatingLabelTextField.placeholder!.count)
#endif

// when
Expand Down Expand Up @@ -236,7 +236,7 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
NSRange(location: 0, length: floatingLabelTextField.placeholder!.count)
#else
var fullRange =
NSRange(location: 0, length: floatingLabelTextField.placeholder!.characters.count)
NSRange(location: 0, length: floatingLabelTextField.placeholder!.count)
#endif

// when
Expand Down Expand Up @@ -298,7 +298,7 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
NSRange(location: 0, length: floatingLabelTextField.placeholder!.count)
#else
var fullRange =
NSRange(location: 0, length: floatingLabelTextField.placeholder!.characters.count)
NSRange(location: 0, length: floatingLabelTextField.placeholder!.count)
#endif

// when
Expand Down Expand Up @@ -351,7 +351,7 @@ class SkyFloatingLabelTextFieldTests: XCTestCase { // swiftlint:disable:this typ
NSRange(location: 0, length: floatingLabelTextField.placeholder!.count)
#else
var fullRange =
NSRange(location: 0, length: floatingLabelTextField.placeholder!.characters.count)
NSRange(location: 0, length: floatingLabelTextField.placeholder!.count)
#endif

// when
Expand Down
22 changes: 7 additions & 15 deletions Sources/SkyFloatingLabelTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,11 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
}

fileprivate func updateTextAligment() {
if isLTRLanguage {
textAlignment = .left
titleLabel.textAlignment = .left
errorLabel.textAlignment = .left
} else {
textAlignment = .right
titleLabel.textAlignment = .right
errorLabel.textAlignment = .right
}

// Override error message default alignment
if let errorLabelAlignment = errorLabelAlignment {
errorLabel.textAlignment = errorLabelAlignment
}
let alignment: NSTextAlignment = isLTRLanguage ? .left : .right
textAlignment = alignment
titleLabel.textAlignment = alignment
errorLabel.textAlignment = alignment
}

// MARK: Animation timing
Expand Down Expand Up @@ -101,7 +92,8 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
/// An `NSTextAlignment` value that determines the error label text alignment.
open var errorLabelAlignment: NSTextAlignment? {
didSet {
updateTextAligment()
// Override error message default alignment
errorLabel.textAlignment = errorLabelAlignment
}
}

Expand Down Expand Up @@ -422,7 +414,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
fileprivate func configureDefaultLineHeight() {
let onePixel: CGFloat = 1.0 / UIScreen.main.scale
lineHeight = 2.0 * onePixel
selectedLineHeight = 2.0 * self.lineHeight
selectedLineHeight = 2.0 * lineHeight
}

// MARK: Responder handling
Expand Down