Reputation: 57
I am learning AsyncDisplayKit(Texture), and I am learning how to layout things, I want to add a simple ASTexNode(UILabel) to ASDKViewController(UIViewController) and the text node is showing up please find the code below.
This is basic TextVC class
import AsyncDisplayKit
class TextVC: ASDKViewController<BaseNode> {
let textNode = ASTextNode()
override init() {
super.init(node: BaseNode())
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
textNode.automaticallyManagesSubnodes = true
textNode.backgroundColor = UIColor.red
textNode.maximumNumberOfLines = 1
textNode.attributedText = NSAttributedString(string: "This is a sample string",
attributes: [NSAttributedString.Key.foregroundColor: UIColor.white,
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 25)])
node.addSubnode(textNode)
node.layoutSpecBlock = { [unowned self] node, constrainedSize in
return ASWrapperLayoutSpec(layoutElement: textNode)
}
// node.layoutSpecBlock = { [unowned self] node, constrainedSize in
// return ASCenterLayoutSpec(centeringOptions: ASCenterLayoutSpecCenteringOptions.XY, sizingOptions: ASCenterLayoutSpecSizingOptions.minimumXY, child: textNode)
// }
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print(String(describing: TextVC.self) + " viewWillAppear called")
}
}
This is BaseNode
import AsyncDisplayKit
class BaseNode: ASDisplayNode {
override init() {
super.init()
self.automaticallyManagesSubnodes = true
self.view.backgroundColor = UIColor.red
}
}
The text node is not showing up on the screen.
Upvotes: 0
Views: 26