iosswifttextfield

How to use "MDCOutlinedTextField" in Swift


I need textfield like below image

enter image description here

so i am using material-components-ios framework, for that i have added textfield in storyboard and given its class name to MDCTextField and code

import UIKit

import MaterialComponents
class LoginVC: UIViewController {

@IBOutlet weak var emailTF: MDCTextField!

var textFieldControllerFloating: MDCTextInputControllerOutlined?

override func viewDidLoad() {
    super.viewDidLoad()
  //  setupEditText()
    
    textFieldControllerFloating = MDCTextInputControllerOutlined(textInput: emailTF)

    textFieldControllerFloating?.activeColor = UIColor.lightGray
    textFieldControllerFloating?.floatingPlaceholderActiveColor = UIColor.green
    textFieldControllerFloating?.normalColor = UIColor.lightGray
    textFieldControllerFloating?.inlinePlaceholderColor = UIColor.lightGray
    
}

with this code o/p coming perfect but showing warning

warning:

'MDCTextField' is deprecated: MDCTextField and its associated classes are deprecated. Please use TextControls instead.

so i have added another framework TextControls here i have added pod 'MaterialComponents/TextControls+OutlinedTextFields' and added textfield in stroyboard and given its class to MDCOutlinedTextField and added below code

 import UIKit
 import MaterialComponents.MaterialTextControls_OutlinedTextFields

class LoginVC: UIViewController {

@IBOutlet weak var emailTF: MDCOutlinedTextField!
@IBOutlet weak var passwordTF: MDCOutlinedTextField!
}
}

but o/p like below: no floating placeholder text and small height as well why?, where am i wrong.. how to get textfield with height 50 and floating placeholder border like above image, please do help.

EDIT: i need eye button for password textfield like this how to do with MDCOutlinedTextField?

enter image description here


Solution

  • As per example try to set label.text property like that

    textField.label.text = "Phone number"
    

    As for text field height you can set it for instance with a constraint in Interface Builder