forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayoutExampleNode.swift
More file actions
145 lines (113 loc) · 4.81 KB
/
Copy pathLayoutExampleNode.swift
File metadata and controls
145 lines (113 loc) · 4.81 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// LayoutExampleNode.swift
// Sample
//
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import AsyncDisplayKit
class LayoutExampleNode: ASDisplayNode {
override required init() {
super.init()
automaticallyManagesSubnodes = true
backgroundColor = .white
}
class func title() -> String {
assertionFailure("All layout example nodes must provide a title!")
return ""
}
class func descriptionTitle() -> String? {
return nil
}
}
class HeaderWithRightAndLeftItems : LayoutExampleNode {
let userNameNode = ASTextNode()
let postLocationNode = ASTextNode()
let postTimeNode = ASTextNode()
required init() {
super.init()
userNameNode.attributedText = NSAttributedString.attributedString(string: "hannahmbanana", fontSize: 20, color: .darkBlueColor())
userNameNode.maximumNumberOfLines = 1
userNameNode.truncationMode = .byTruncatingTail
postLocationNode.attributedText = NSAttributedString.attributedString(string: "Sunset Beach, San Fransisco, CA", fontSize: 20, color: .lightBlueColor())
postLocationNode.maximumNumberOfLines = 1
postLocationNode.truncationMode = .byTruncatingTail
postTimeNode.attributedText = NSAttributedString.attributedString(string: "30m", fontSize: 20, color: .lightGray)
postTimeNode.maximumNumberOfLines = 1
postTimeNode.truncationMode = .byTruncatingTail
}
override class func title() -> String {
return "Header with left and right justified text"
}
override class func descriptionTitle() -> String? {
return "try rotating me!"
}
}
class PhotoWithInsetTextOverlay : LayoutExampleNode {
let photoNode = ASNetworkImageNode()
let titleNode = ASTextNode()
required init() {
super.init()
backgroundColor = .clear
photoNode.url = URL(string: "http://texturegroup.org/static/images/layout-examples-photo-with-inset-text-overlay-photo.png")
photoNode.willDisplayNodeContentWithRenderingContext = { context, drawParameters in
let bounds = context.boundingBoxOfClipPath
UIBezierPath(roundedRect: bounds, cornerRadius: 10).addClip()
}
titleNode.attributedText = NSAttributedString.attributedString(string: "family fall hikes", fontSize: 16, color: .white)
titleNode.truncationAttributedText = NSAttributedString.attributedString(string: "...", fontSize: 16, color: .white)
titleNode.maximumNumberOfLines = 2
titleNode.truncationMode = .byTruncatingTail
}
override class func title() -> String {
return "Photo with inset text overlay"
}
override class func descriptionTitle() -> String? {
return "try rotating me!"
}
}
class PhotoWithOutsetIconOverlay : LayoutExampleNode {
let photoNode = ASNetworkImageNode()
let iconNode = ASNetworkImageNode()
required init() {
super.init()
photoNode.url = URL(string: "http://texturegroup.org/static/images/layout-examples-photo-with-outset-icon-overlay-photo.png")
iconNode.url = URL(string: "http://texturegroup.org/static/images/layout-examples-photo-with-outset-icon-overlay-icon.png")
iconNode.imageModificationBlock = { image in
let profileImageSize = CGSize(width: 60, height: 60)
return image.makeCircularImage(size: profileImageSize, borderWidth: 10)
}
}
override class func title() -> String {
return "Photo with outset icon overlay"
}
override class func descriptionTitle() -> String? {
return nil
}
}
class FlexibleSeparatorSurroundingContent : LayoutExampleNode {
let topSeparator = ASImageNode()
let bottomSeparator = ASImageNode()
let textNode = ASTextNode()
required init() {
super.init()
topSeparator.image = UIImage.as_resizableRoundedImage(withCornerRadius: 1.0, cornerColor: .black, fill: .black)
textNode.attributedText = NSAttributedString.attributedString(string: "this is a long text node", fontSize: 16, color: .black)
bottomSeparator.image = UIImage.as_resizableRoundedImage(withCornerRadius: 1.0, cornerColor: .black, fill: .black)
}
override class func title() -> String {
return "Top and bottom cell separator lines"
}
override class func descriptionTitle() -> String? {
return "try rotating me!"
}
}