Utku
Utku

Reputation: 173

Is that possible to override MDCTextInputControllerFilled's borderView's frame?

I have a design which is as like as possible with MDCTextField(with controller MDCTextInputControllerFilled). I inspected the components and I think me should override controller's but why?

If I'm on wrong way, can you help me to handle this problem?

My testing code is below

tfc1?.placeholderText = "Test"
tfc1?.borderFillColor = UIColor.brown.withAlphaComponent(1)
if let f = tfc1?.textInput?.borderView?.frame {
    tfc1?.textInput?.borderView?.frame = CGRect(
        x: f.origin.x,
        y: f.origin.y + 25,
        width: f.width,
         height: f.height + 25
    )
}

Upvotes: 0

Views: 444

Answers (1)

Will Larche
Will Larche

Reputation: 3149

Thanks for your patience. I'm assuming only single line matters which makes this simpler.

It looks like you want a text field that's centered in a container that's 25 taller than the field.

I would subclass MDCTextInputControllerFilled. In the subclass override textInsets:. Here's a start in Objective-C:

- (UIEdgeInsets)textInsets:(UIEdgeInsets)defaultInsets {
  UIEdgeInsets textInsets = [super textInsets:defaultInsets];
  textInsets.top = 12.5;
  textInsets.bottom = 12.5;

  return textInsets;
}

Don't adjust the frame of the border view directly. It gets its information from a lot of sources. The one that matters to you is the insets.

Upvotes: 1

Related Questions