0

i write these lines of codes to change background color of filled textfield, but it not work:

import MaterialComponents

...

@IBOutlet weak var textfield: MDCFilledTextField!

let scheme = MDCContainerScheme()
scheme.colorScheme.backgroundColor = .red
scheme.colorScheme.onBackgroundColor = .green

textfield.label.text = "Phone number"
textfield.placeholder = "555-555-55"

textfield.applyTheme(withScheme: scheme)
textfield.sizeToFit()

and finally it looks like this:

enter image description here

but when i change primaryColor scheme.colorScheme.primaryColor = .red it works. ( just primary color )

MMG
  • 3,226
  • 5
  • 16
  • 43
Sajjad
  • 1,536
  • 2
  • 17
  • 31

1 Answers1

4

You can change the colors like following:

    let tf = MDCFilledTextField()

    // Background color
    tf.setFilledBackgroundColor(.clear, for: .normal)
    tf.setFilledBackgroundColor(Colors.textFieldActiveBackground, for: .editing)

    // Floating label color
    tf.setFloatingLabelColor(Colors.pinDotActive, for: .editing)
    tf.setFloatingLabelColor(Colors.grayScale800, for: .normal)
    
    // Underline color
    tf.setUnderlineColor(Colors.pinDotActive, for: .editing)
    tf.setUnderlineColor(Colors.grayScale800, for: .normal)
Abu-Bakr
  • 408
  • 6
  • 12