7

I have open the issue at MaterialComponents on Github already but seem like no answer yet. The problem is when I click the textfield to be active then I click outside, it was working fine but when I repeat doing that, the placeholder for the textfield will be always on the top

Here is the problem as an image

When textfield didload: enter image description here

When textfield active: enter image description here

When we repeat click on textfield then click outside again it will look like this enter image description here

Here is the code:

@IBOutlet weak var textfieldFloating: MDCTextField!
let tf = MDCTextInputControllerOutlined()

override func viewDidLoad() {
        super.viewDidLoad()
        textfieldFloating.leftView = UIImageView(image: UIImage(named: "ic_lock_outline_white_18pt"))
        textfieldFloating.leftViewMode = .always
        textfieldFloating.placeholder = "Placeholder"
        tf.textInput = textfieldFloating
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
    }
Anonymous-E
  • 827
  • 11
  • 29
  • Unfortunately, as it is a bug within the material-components it is best if you wait until they fix the bug themselves – AD Progress Oct 10 '18 at 10:46
  • 2
    I have recreated your code and it definitely looks like a bug to me withing MaterialComponents. Probably something to do with the animation of the placeholder as if you click fast it has not finished animating however it's position coordinates are already updated. – AD Progress Oct 10 '18 at 11:07
  • thank for telling me. I'm afraid that I forgot somewhere inside my code that can be the cause of this problem, but if the problem is from the library itself can you suggest me that which library that could be work like this though? I'm trying to use SkyFloatingLabelTextField but their animation not as smooth as material component – Anonymous-E Oct 11 '18 at 00:21
  • @Anonymous-E is this issue already fixed? I'm using swift 4.2 but maybe in swift 5 it's already fixed, do you find any good alternative for this textfield, I'm also encountering the same problem. – Dylan Apr 27 '20 at 18:35
  • 1
    @MarkDylanBMercado I've updated to the latest and it's working fine now – Anonymous-E Apr 28 '20 at 08:10

1 Answers1

-1

I would personally go for https://github.com/raulriera/TextFieldEffects CocoaPod it has a lot of different styles which you can use, and best of all it is very simple tu use.

just create a pod file with pod init then add this:

use_frameworks!
pod 'TextFieldEffects'

to your pods and install it with pod install from terminal.

To use it:

The library is a simple drop-in, as soon as you set your subclass to one of the effects and your module to TextFieldEffects you will be able to see all the IBDesignable settings in the storyboard.

You can also use it programmatically without storyboards as you wish:

let textField = KaedeTextField(frame: textFieldFrame)
textField.placeholderColor = .darkGrayColor()
textField.foregroundColor = .lightGrayColor()

view.addSubView(textField)
AD Progress
  • 4,190
  • 1
  • 14
  • 33
  • 1
    Before I use MDC textfield, I've tried to look at this library too but their animation is not matched with Material Component though because I'm am IOS dev and the project that I working on is need to match with the Android version though, anyway thank for answering. your answer might be useful to other people though! I'll upvote this one – Anonymous-E Oct 12 '18 at 02:17