2

enter image description hereI have assigned a class named MDCMultilineTextField for Uiview from the storyboard. This class is used for Multiline 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.

        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
            }
    }
Sanpreet Singh
  • 91
  • 2
  • 10

3 Answers3

2

I have used MDCOutlinedTextArea and went through the same problem. 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
ajith Kumark
  • 333
  • 1
  • 3
  • 16
0

You can assign MDCMultilineTextField.layoutDelegate to UIView container. It will change the container size based on MDCMultilineTextField height.

-1

try this

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