Commit 85cae46a by Daniel Dahan

issue-338: fixed where programmatically setting text did not display placeholderLabel

parent 23dde70e
...@@ -106,9 +106,9 @@ class ViewController: UIViewController, TextFieldDelegate { ...@@ -106,9 +106,9 @@ class ViewController: UIViewController, TextFieldDelegate {
/// Prepares the name TextField. /// Prepares the name TextField.
private func prepareNameField() { private func prepareNameField() {
nameField = MTextField() nameField = MTextField()
nameField.placeholder = "Name" nameField.placeholder = "Name yyy yyy "
nameField.detail = "Error, incorrect password. yy ypp ggg" nameField.detail = "Error, incorrect password. yy ypp ggg"
nameField.placeholderTextColor = MaterialColor.green.base nameField.text = "Testing Text ppp ppp"
view.addSubview(nameField) view.addSubview(nameField)
nameField.translatesAutoresizingMaskIntoConstraints = false nameField.translatesAutoresizingMaskIntoConstraints = false
......
...@@ -259,8 +259,10 @@ public class MTextField : UITextField { ...@@ -259,8 +259,10 @@ public class MTextField : UITextField {
/// Handles the text editing did end state. /// Handles the text editing did end state.
public func handleEditingDidEnd() { public func handleEditingDidEnd() {
dividerEditingDidEndAnimation() dividerEditingDidEndAnimation()
if true == text?.isEmpty {
placeholderEditingDidEndAnimation() placeholderEditingDidEndAnimation()
} }
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
...@@ -290,6 +292,10 @@ public class MTextField : UITextField { ...@@ -290,6 +292,10 @@ public class MTextField : UITextField {
public func layoutPlaceholderLabel() { public func layoutPlaceholderLabel() {
if true == text?.isEmpty { if true == text?.isEmpty {
placeholderLabel.frame = bounds placeholderLabel.frame = bounds
} else if CGAffineTransformIsIdentity(placeholderLabel.transform) {
placeholderLabel.frame = bounds
placeholderLabel.transform = CGAffineTransformScale(placeholderLabel.transform, 0.75, 0.75)
placeholderLabel.frame.origin = CGPointMake(0, -16)
} }
} }
...@@ -314,11 +320,11 @@ public class MTextField : UITextField { ...@@ -314,11 +320,11 @@ public class MTextField : UITextField {
/// The animation for the placeholder when editing begins. /// The animation for the placeholder when editing begins.
public func placeholderEditingDidBeginAnimation() { public func placeholderEditingDidBeginAnimation() {
placeholderLabel.textColor = placeholderTextColor placeholderLabel.textColor = placeholderTextColor
if true == text?.isEmpty { if CGAffineTransformIsIdentity(placeholderLabel.transform) {
UIView.animateWithDuration(0.15, animations: { [weak self] in UIView.animateWithDuration(0.15, animations: { [weak self] in
if let s: MTextField = self { if let s: MTextField = self {
s.placeholderLabel.transform = CGAffineTransformScale(s.placeholderLabel.transform, 0.75, 0.75) s.placeholderLabel.transform = CGAffineTransformScale(s.placeholderLabel.transform, 0.75, 0.75)
s.placeholderLabel.frame = CGRectMake(0, -16, s.bounds.width, 12) s.placeholderLabel.frame.origin = CGPointMake(0, -16)
} }
}) })
} }
...@@ -326,7 +332,6 @@ public class MTextField : UITextField { ...@@ -326,7 +332,6 @@ public class MTextField : UITextField {
/// The animation for the placeholder when editing ends. /// The animation for the placeholder when editing ends.
public func placeholderEditingDidEndAnimation() { public func placeholderEditingDidEndAnimation() {
if true == text?.isEmpty {
UIView.animateWithDuration(0.15, animations: { [weak self] in UIView.animateWithDuration(0.15, animations: { [weak self] in
if let s: MTextField = self { if let s: MTextField = self {
s.placeholderLabel.transform = CGAffineTransformIdentity s.placeholderLabel.transform = CGAffineTransformIdentity
...@@ -334,7 +339,6 @@ public class MTextField : UITextField { ...@@ -334,7 +339,6 @@ public class MTextField : UITextField {
} }
}) })
} }
}
/// Prepares the divider. /// Prepares the divider.
private func prepareDivider() { private func prepareDivider() {
...@@ -345,13 +349,14 @@ public class MTextField : UITextField { ...@@ -345,13 +349,14 @@ public class MTextField : UITextField {
/// Prepares the placeholderLabel. /// Prepares the placeholderLabel.
private func preparePlaceholderLabel() { private func preparePlaceholderLabel() {
placeholderLabel = UILabel() placeholderLabel = UILabel(frame: CGRectZero)
placeholderLabel.font = font
addSubview(placeholderLabel) addSubview(placeholderLabel)
} }
/// Prepares the detailLabel. /// Prepares the detailLabel.
private func prepareDetailLabel() { private func prepareDetailLabel() {
detailLabel = UILabel() detailLabel = UILabel(frame: CGRectZero)
detailLabel.font = RobotoFont.regularWithSize(12) detailLabel.font = RobotoFont.regularWithSize(12)
addSubview(detailLabel) addSubview(detailLabel)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment