Skip to content

Instantly share code, notes, and snippets.

@codeOfRobin
Created May 20, 2018 18:37
Show Gist options
  • Save codeOfRobin/2b95ccb9d9d32b6a11b8a2b1d8bae523 to your computer and use it in GitHub Desktop.
Save codeOfRobin/2b95ccb9d9d32b6a11b8a2b1d8bae523 to your computer and use it in GitHub Desktop.
//
// CountNode.swift
// ChannelExample
//
// Created by Robin Malhotra on 22/04/18.
// Copyright © 2018 Robin Malhotra. All rights reserved.
//
import AsyncDisplayKit
class CountNode: ASDisplayNode {
let countLabel = ASTextNode()
let horizontalPadding: CGFloat = 13.0
let verticalPadding: CGFloat = 2.0
init(count: Int) {
super.init()
self.countLabel.attributedText = NSAttributedString.init(string: "\(count)", attributes: Styles.Text.pillText)
self.automaticallyManagesSubnodes = true
}
override func didLoad() {
super.didLoad()
self.backgroundColor = Styles.Colors.pillBackground
self.view.clipsToBounds = true
}
override func layoutDidFinish() {
super.layoutDidFinish()
self.layer.cornerRadius = self.frame.height / 2
}
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
return ASInsetLayoutSpec(insets: UIEdgeInsets.init(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding), child: countLabel)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment