Skip to content

Instantly share code, notes, and snippets.

@christianselig
Created March 29, 2020 00:17
Show Gist options
  • Save christianselig/83cec27756f9a2a62469a72de013b3c7 to your computer and use it in GitHub Desktop.
Save christianselig/83cec27756f9a2a62469a72de013b3c7 to your computer and use it in GitHub Desktop.
import UIKit
import AsyncDisplayKit
class CommentPreviewViewController: ASViewController<ASDisplayNode> {
let rootNode = ASDisplayNode()
let textNode = ASTextNode()
init() {
super.init(node: rootNode)
textNode.attributedText = NSAttributedString(string: "Lorem ipsum dolor sit amet.", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15.0)])
rootNode.automaticallyManagesSubnodes = true
rootNode.layoutSpecBlock = { (node, constrainedSize) in
return ASInsetLayoutSpec(insets: UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0), child: self.textNode)
}
}
required init?(coder aDecoder: NSCoder) { fatalError("\(#file) does not implement coder.") }
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let layout = rootNode.layoutThatFits(ASSizeRangeMake(CGSize(width: view.bounds.width, height: CGFloat.greatestFiniteMagnitude)))
print(layout.size.height) // Error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment