Vinícius Barcelos
Vinícius Barcelos

Reputation: 401

How to change top and bottom padding of text in MaterialDesign Overlined Textfield in iOS?

I'm trying to change padding top and padding bottom of text in material design text field.

I already try to apply shape and typography schemes but it had no effect.

textfield with default padding

This is my code:

// Outlet
@IBOutlet weak var nameTextField: MDCTextField!

// Implementation
nameTextField.placeholder = "Nome"
nameTextField.delegate = self
let nameTextFieldController = MDCTextInputControllerOutlined(textInput: nameTextField)

How can i change these spaces?

**** UPDATE ****

After change textRect by overiding MDCTextField i achieve following result. That is a a great advance. But how can i change the size of border to match text?

enter image description here

Upvotes: 1

Views: 1233

Answers (1)

Andrew21111
Andrew21111

Reputation: 908

If you can extend the MDCTextField class, then override this method:

        override func textRect(forBounds bounds: CGRect) -> CGRect { 
         return bounds.inset(by: UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)) 
        } 

Change top and bottom values as you wish.

If you cannot access/modify or extend the MDCTextField class, or if it already has its textRect(:forBounds) implementation, you can create your own UITextField class such as:

       class MyTextField: UITextField{
           ...
       }

NOTE: You can even try to inherit MDCTextField class:

       class MyTextField: MDCTextField{
           ...
       }

Upvotes: 2

Related Questions