Andrew Overton 4745d80b40
[TextFields] Add accessibility docs for MDCTextField (#4498)
* Add accessibility docs for MDCTextField

* Try to fix readme situation
2018-07-12 15:53:36 -04:00

1.8 KiB

Text Fields Typography Theming

You can theme a text field with your app's typography scheme using the TypographyThemer extension.

You must first add the Typography Themer extension to your project:

pod 'MaterialComponents/TextFields+TypographyThemer'

Swift

// Step 1: Import the TypographyThemer extension
import MaterialComponents.MaterialTextFields_TypographyThemer

// Step 2: Create or get a typography scheme
let typographyScheme = MDCTypographyScheme()

// Step 3: Apply the typography scheme to your component

// Applying to a text field
MDCTextFieldTypographyThemer.apply(typographyScheme, to: textField)

// Applying to an input controller
MDCTextFieldTypographyThemer.apply(typographyScheme, to: inputController)

// Applying to a specific class type of inputController
MDCTextFieldTypographyThemer.apply(typographyScheme, 
    toAllControllersOfClass: MDCTextInputControllerUnderline.self) 

Objective-C

// Step 1: Import the TypographyThemer extension
#import "MaterialTextFields+TypographyThemer.h"

// Step 2: Create or get a typography scheme
id<MDCTypographyScheming> typographyScheme = [[MDCTypographyScheme alloc] init];

// Step 3: Apply the typography scheme to your component

// Applying to a text field
[MDCTextFieldTypographyThemer applyTypographyScheme:typographyScheme toTextInput:textField];

// Applying to an input controller
[MDCTextFieldTypographyThemer applyTypographyScheme:typographyScheme
                              toTextInputController:inputController];

// Applying to a specific class type of inputController
[MDCTextFieldTypographyThemer applyTypographyScheme:typographyScheme 
                   toAllTextInputControllersOfClass:[MDCTextInputControllerUnderline class]];