ios - DTAttributedTextView 不重新布局

标签 ios swift dtcoretext

当 DTAttributedTextView 的框架更改时, View 内的内容(文本)不会重新布局。我的 tableView 单元格中有 TextView ,其高度由布局约束指定,我在代码中更改了该值。宽度会根据单元格宽度的约束自动变化。

我尝试手动调用setNeedsLayoutlayoutIfNeededrelayoutTextsetNeedsDisplay。似乎没有什么帮助。为什么内容布局会这样锁定?

这似乎适用于高度,但不适用于宽度:

override func layoutSubviews() {
    super.layoutSubviews()

    comment.attributedTextContentView.layoutFrame = DTCoreTextLayoutFrame(
        frame: comment.frame,
        layouter: comment.attributedTextContentView.layouter)
    comment.relayoutText()
}

最佳答案

调用relayoutText之前需要将layouter设置为nil

comment.attributedTextContentView.layoutFrame = DTCoreTextLayoutFrame(
    frame: comment.frame,
    layouter: comment.attributedTextContentView.layouter)
//gets rid of cached layouter
comment.layouter = nil
comment.relayoutText()

关于ios - DTAttributedTextView 不重新布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33691992/

相关文章:

ios - iOS:如何在键盘按键后停止接收keyboardWillShowNotification

ios - 使用外部类更改 tableView touch 上的 View Controller

ios - 当一个 View Controller 中有多个表时,如何在 UITableViewCell 中获取多个文本字段引用?

Swift:填充 AutoreleasingUnsafeMutablePointer<NSDictionary?>

ios - 框架只能在模拟器上运行,不能在设备上运行

swift - 如何在 Swift 3 的 DTCoreText 中显示与 html 内联的图像

iphone - 如何在长NSString中找到动态数字?

ios - 从iOS上传MP4视频给我一个MOV

ios - 如何从 AppDelegate 显示表单?

ios - 如何访问 MKMapItem 的类别或类型