-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageButtonVC.swift
69 lines (57 loc) · 1.75 KB
/
ImageButtonVC.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// ImageButtonVC.swift
// pinknoise
//
// Created by Adam Tait on 2/20/18.
// Copyright © 2018 Sisterical Inc. All rights reserved.
//
import Foundation
import AsyncDisplayKit
class ImageButtonVC : ButtonVC
{
static let defaultImageStyle : Style = [StyleType.imageName : "AppIcon"]
// initializers
static func newImageNode(style: Style) -> ASImageNode
{
let n = ASImageNode()
let imageName = style[.imageName] as! String
n.image = UIImage(named: imageName)!.resizableImage(withCapInsets: .zero, resizingMode: .stretch)
n.contentMode = .center
n.clipsToBounds = true
return n
}
override init(node: ASControlNode,
style: Style = [:])
{
let s = ASDisplayNode.cascade(styles: [ImageButtonVC.defaultImageStyle, style])
super.init(node: node, style: s)
}
convenience init(style: Style)
{
let s = ASDisplayNode.cascade(styles: [ImageButtonVC.defaultImageStyle, style])
let n = Layout.node(imageNode: ImageButtonVC.newImageNode(style: s), style: s)
self.init(node: n, style: s)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
// layout
extension ImageButtonVC
{
enum Layout
{
static func node(imageNode : ASImageNode,
style : Style)
-> ASControlNode
{
let n = ASControlNode()
n.automaticallyManagesSubnodes = true
n.layoutSpecBlock = { node, size in
let insets = style[.insets] as! UIEdgeInsets
return ASInsetLayoutSpec(insets: insets, child: imageNode)
}
return n
}
}
}