Created
September 25, 2019 09:04
-
-
Save wendyliga/cbdbfb39f781a426baba75956de46ab3 to your computer and use it in GitHub Desktop.
TextureGram StoryCell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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