【问题标题】:Swift: Remove contentInset for UITextView in TableViewCellsSwift:删除 TableViewCells 中 UITextView 的 contentInset
【发布时间】:2017-12-20 10:36:17
【问题描述】:

我正在尝试将我放置在 tableViewCells 中的 textView 的 contentInsets 设置为零,以便我可以将我的文本与标签和 imageView 气泡对齐。我当前的实现看起来像这样。

我采用了这篇文章中的解决方案,但似乎不适用于我的情况。 Blank space at top of UITextView in iOS 10

上面帖子中的解决方案是针对uiviews的,但我的是在tableViewCell中,tableViewCell中没有自动AdjustsScrollViewInsets。

这里有什么帮助吗?

【问题讨论】:

    标签: swift uikit


    【解决方案1】:

    contentInset 设置为零将不起作用,因为它已应用于UIScrollView

    您要删除的间距实际上由NSTextContainer 内部的UITextView 控制。

    要删除间距,只需将其放入您的单元格中(例如在 awakeFromNib 中):

    override func awakeFromNib() {
        super.awakeFromNib()
    
        // Removes UITextView inner spacing
        textView.textContainerInset = .zero
        textView.textContainer.lineFragmentPadding = 0.0
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-11
      • 1970-01-01
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多