【问题标题】:Is that possible to override MDCTextInputControllerFilled's borderView's frame?是否可以覆盖 MDCTextInputControllerFilled 的边框视图的框架?
【发布时间】:2018-05-08 07:48:45
【问题描述】:

我有一个尽可能与 MDCTextField 相似的设计(带有控制器 MDCTextInputControllerFilled)。我检查了组件,我认为我应该覆盖控制器,但为什么?

如果我走错路了,你能帮我解决这个问题吗?

我的测试代码如下

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
    )
}

【问题讨论】:

  • 你能添加一张你想要的图片吗?
  • 您好,谢谢您的回复。喜欢这张图片ibb.co/dhYDdy

标签: ios swift material-components material-components-ios


【解决方案1】:

感谢您的耐心等待。我假设只有单行很重要,这使得这更简单。

您似乎想要一个位于比该字段高 25 的容器中居中的文本字段。

我会继承MDCTextInputControllerFilled。在子类中覆盖textInsets:。这是 Objective-C 的开始:

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

  return textInsets;
}

不要直接调整边框视图的框架。它从很多来源获取信息。对您来说最重要的是插图。

【讨论】:

  • 感谢您的回复。我得到了你的方式,这对我来说没问题。再次感谢您。
猜你喜欢
  • 2020-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多