问题是,当我在textView中输入一些文本时,文本会超出其设置的框架.我以编程方式创建所有内容.
创建UITextView:
let descriptionTextView: UITextView = {
let textView = UITextView()
textView.backgroundColor = UIColor.customDarkGrayColor
textView.text = "News Description"
textView.textColor = UIColor.lightGray
textView.font = UIFont.systemFont(ofSize: 15)
textView.textContainerInset = UIEdgeInsets(top: 10, left: 16, bottom: 0, right: 16)
textView.autocorrectionType = .no
textView.setDefaultShadow()
return textView
}()
Run Code Online (Sandbox Code Playgroud)
使用我的自定义方法添加为子视图和设置约束:
addSubview(descriptionTextView)
descriptionTextView.anchor(top: titleTextField.bottomAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, paddingTop: 10, paddingLeft: 20, paddingBottom: 0, paddingRight: 20, width: 0, height: 80)
Run Code Online (Sandbox Code Playgroud)