I 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
}
}
我使用过 MDCOutlinedTextArea 并遇到了同样的问题。指定文本区域高度的唯一方法是设置最小和最大行数。
您需要计算可以在视图中显示的文本行数,如下所示。
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)