简体   繁体   English

如何增加 MDCTextInputControllerOutlinedTextArea 的高度

[英]How To Increase the height of MDCTextInputControllerOutlinedTextArea

在此处输入图片说明 I have assigned a class named MDCMultilineTextField for Uiview from the storyboard.我从情节提要中为 Uiview 分配了一个名为MDCMultilineTextField的类。 This class is used for Multiline TextView.此类用于多行 TextView。 My Uiview height is 400(not fix) but my UiView border is not same as height, Please verify my code and you can see screenshot below.我的 Uiview 高度为 400(未修复)但我的 UiView 边框与高度不同,请验证我的代码,您可以在下面看到屏幕截图。

        import MaterialComponents    

        @IBOutlet var viewTextView: MDCMultilineTextField!
        @IBOutlet var btnDone: UIButton!
        var notes=""
        var dismissView: ((_ text:String) -> Void)?
        var desc: MDCTextInputControllerOutlinedTextArea?
       override func viewDidLoad()
        {
           desc = MDCTextInputControllerOutlinedTextArea(textInput: viewTextView)
           viewTextView.placeholder="Description"
           viewTextView.backgroundColor = UIColor.yellow
           if notes != ""
            {
                textView.text = notes
                viewTextView.text = notes
            }
    }

You can assign MDCMultilineTextField.layoutDelegate to UIView container.您可以将MDCMultilineTextField.layoutDelegate分配给 UIView 容器。 It will change the container size based on MDCMultilineTextField height.它将根据MDCMultilineTextField高度更改容器大小。

I have used MDCOutlinedTextArea and went through the same problem.我使用过 MDCOutlinedTextArea 并遇到了同样的问题。 Only way to specify text area height is by setting minimum and maximum number of lines.指定文本区域高度的唯一方法是设置最小和最大行数。 And you need to calculate the number of text rows that can be displayed in your view as below.并且您需要计算可以在您的视图中显示的文本行数,如下所示。

    inpOutlineTextArea.textView.text = "Description"

    let lineHeight =  inpOutlineTextArea.textView.font!.lineHeight  // height for one line in textview
    let totalVisibleRows = yourView.frame.height / lineHeight   // number of rows that can be shown in your view
    print("lines -- \(totalVisibleRows)")

    inpOutlineTextArea.maximumNumberOfVisibleRows = totalVisibleRows
    inpOutlineTextArea.minimumNumberOfVisibleRows = totalVisibleRows

尝试这个

NSLayoutConstraint(item: multilineTextField.textView, attribute: .bottom, relatedBy: .equal, toItem: multilineTextField.borderView, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM