Reputation: 827
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 we repeat click on textfield then click outside again it will look like this
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)
}
Upvotes: 7
Views: 2762
Reputation: 5086
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)
Upvotes: -1