2017-07-15 69 views
0

我正在嘗試將contentInsets設置爲零,以便將我的textView放置在我的tableViewCells中,以便我可以將我的文本與標籤和imageView泡泡對齊。我目前的實施看起來像這樣。 enter image description hereSwift:刪除TableInCells中的UITextView contentInset

我在這篇文章中採用瞭解決方案,但似乎沒有爲我的案件工作。 Blank space at top of UITextView in iOS 10

上述帖子中的解決方案是針對uiviews的,但是我的解決方案是在tableViewCell中,它自動地調用了ScrollViewInsets,它在tableViewCell中不可用。

這裏有任何幫助嗎?

回答

0

contentInset設置爲零將不起作用,因爲它適用於UIScrollView

要移除的間距實際上由UITextView內的NSTextContainer控制。

要刪除的間距只是把這個在你的細胞(例如內部awakeFromNib):

override func awakeFromNib() { 
    super.awakeFromNib() 

    // Removes UITextView inner spacing 
    textView.textContainerInset = .zero 
    textView.textContainer.lineFragmentPadding = 0.0 
}