Peter 9bc996374f Add 'submodules/AsyncDisplayKit/' from commit '02bedc12816e251ad71777f9d2578329b6d2bef6'
git-subtree-dir: submodules/AsyncDisplayKit
git-subtree-mainline: d06f423e0ed3df1fed9bd10d79ee312a9179b632
git-subtree-split: 02bedc12816e251ad71777f9d2578329b6d2bef6
2019-06-11 18:42:43 +01:00

41 lines
1.3 KiB
Swift

//
// PhotoWithInsetTextOverlay.swift
// Texture
//
// Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
import AsyncDisplayKit
public class PhotoWithInsetTextOverlay: ASDisplayNode, ASPlayground {
public let photoNode = ASNetworkImageNode()
public let titleNode = ASTextNode()
override public init() {
super.init()
backgroundColor = .white
automaticallyManagesSubnodes = true
setupNodes()
}
private func setupNodes() {
photoNode.url = URL(string: "http://asyncdisplaykit.org/static/images/layout-examples-photo-with-inset-text-overlay-photo.png")
photoNode.backgroundColor = .black
titleNode.backgroundColor = .blue
titleNode.maximumNumberOfLines = 2
titleNode.truncationAttributedText = NSAttributedString.attributedString(string: "...", fontSize: 16, color: .white, firstWordColor: nil)
titleNode.attributedText = NSAttributedString.attributedString(string: "family fall hikes", fontSize: 16, color: .white, firstWordColor: nil)
}
// This is used to expose this function for overriding in extensions
override public func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
return ASLayoutSpec()
}
public func show() {
display(inRect: CGRect(x: 0, y: 0, width: 120, height: 120))
}
}