Skip to content

Instantly share code, notes, and snippets.

@wendyliga
Created September 25, 2019 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wendyliga/cbdbfb39f781a426baba75956de46ab3 to your computer and use it in GitHub Desktop.
Save wendyliga/cbdbfb39f781a426baba75956de46ab3 to your computer and use it in GitHub Desktop.
TextureGram StoryCell
import AsyncDisplayKit
class StoryCell: ASCellNode {
private let story: Story
// MARK: - Nodes
private let userPicture: ASImageNode
private let userName: ASTextNode
init(story: Story) {
self.story = story
userPicture = ASImageNode()
userPicture.image = story.user.userPhoto
userPicture.style.preferredSize = CGSize(width: 55, height: 55)
userPicture.cornerRadius = 55/2
userName = ASTextNode()
userName.attributedText = NSAttributedString.subtitle(story.user.username)
userName.maximumNumberOfLines = 1
super.init()
self.automaticallyManagesSubnodes = true
self.style.width = ASDimension(unit: .points, value: 55)
self.style.height = ASDimension(unit: .fraction, value: 1)
}
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
let mainStack = ASStackLayoutSpec(direction: .vertical,
spacing: 8,
justifyContent: .center,
alignItems: .center,
children: [userPicture, userName])
return mainStack
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment