2017-09-19 31 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

由於這類問題,我通常使用包裝視圖來顯示陰影。 –