2017-09-19 32 views
0

问题是,当我在textView 中输入一些文本时,文本将从其设置的框架中移出。 虽然我以编程方式创建一切。UITextView中的文本超出其框架Swift 3

创建的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 
}() 

添加为子视图并设置限制使用我的自定义方法:

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) 

Check the bug here

回答

0

在哪里寻找到一个可能的想法:

  • UITextView目前是滚动的,因此文本容器有高度
  • 既然你添加阴影没有限制,你可能设置masksToBoundsclipsToBoundstrue这就是为什么文本显示视图框外。

让我知道是否有帮助。干杯!

+0

非常感谢你给我正确的提示! 问题在于您刚刚说过的设置自定义阴影。我刚刚删除,现在一切正常! :) –

+0

很高兴帮助!快乐编码:) –

+0

由于这类问题,我通常使用包装视图来显示阴影。 –