Shaikh
Shaikh

Reputation: 45

MaterialComponents pod warning swift ios

Working on textfield with floating labels with the help of MaterialComponent pod.Textfield class showing warning like MDCTextField' is deprecated: MDCTextField and its associated classes are deprecated. Please use TextControls instead.Can any one help me how i can fix this. enter image description here

Upvotes: 1

Views: 329

Answers (1)

tomerpacific
tomerpacific

Reputation: 6465

The warning you are seeing in the IDE is telling you to use TextControls instead of MDCTextField. If you go to Material UI's documentation, you can see that you need to follow these steps to use TextControls:

  1. Add the relevant pods to your Podfile:

    pod 'MaterialComponents/TextControls+FilledTextAreas'
    
    pod 'MaterialComponents/TextControls+FilledTextFields'
    
    pod 'MaterialComponents/TextControls+OutlinedTextAreas'
    
    pod 'MaterialComponents/TextControls+OutlinedTextFields'
    
  2. Run pod install

  3. In the class you want to use the UI component, add the relevant imports:

    import MaterialComponents.MaterialTextControls_FilledTextAreas
    
    import MaterialComponents.MaterialTextControls_FilledTextFields
    
    import MaterialComponents.MaterialTextControls_OutlinedTextAreas
    
    import MaterialComponents.MaterialTextControls_OutlinedTextFields
    
  4. To replace your OutlinedTextField, you can use:

    let textField = MDCOutlinedTextField(frame: estimatedFrame)
    
    textField.label.text = "Phone number"
    
    textField.placeholder = "555-555-5555"
    
    textField.leadingAssistiveLabel.text = "This is helper text"
    
    textField.sizeToFit()
    
    view.addSubview(textField)
    

For other examples, you can head over to the documentation linked above.

Upvotes: 0

Related Questions