FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AsyncDisplayKit/AsyncDisplayKit/TextKit/ASTextKitComponents.m at master · Xinchi/AsyncDisplayKit · GitHub
Xinchi
/
AsyncDisplayKit
Public
forked from
facebookarchive/AsyncDisplayKit
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
AsyncDisplayKit
/
AsyncDisplayKit
/
TextKit
/
ASTextKitComponents.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (52 loc) · 2.78 KB
Breadcrumbs
AsyncDisplayKit
/
AsyncDisplayKit
/
TextKit
/
ASTextKitComponents.m
Copy path
File metadata and controls
69 lines (52 loc) · 2.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
//
ASTextKitComponents.m
//
AsyncDisplayKit
//
//
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.
//
#
import
"
ASTextKitComponents.h
"
@interface
ASTextKitComponents
()
//
read-write redeclarations
@property
(
nonatomic
,
strong
,
readwrite
)
NSTextStorage
*textStorage;
@property
(
nonatomic
,
strong
,
readwrite
)
NSTextContainer
*textContainer;
@property
(
nonatomic
,
strong
,
readwrite
)
NSLayoutManager
*layoutManager;
@end
@implementation
ASTextKitComponents
+ (
instancetype
)
componentsWithAttributedSeedString
:
(
NSAttributedString
*)
attributedSeedString
textContainerSize
:
(CGSize)
textContainerSize
{
NSTextStorage
*textStorage = attributedSeedString ? [[
NSTextStorage
alloc
]
initWithAttributedString:
attributedSeedString] : [[
NSTextStorage
alloc
]
init
];
return
[
self
componentsWithTextStorage:
textStorage
textContainerSize:
textContainerSize
layoutManager:
[[
NSLayoutManager
alloc
]
init
]];
}
+ (
instancetype
)
componentsWithTextStorage
:
(
NSTextStorage
*)
textStorage
textContainerSize
:
(CGSize)
textContainerSize
layoutManager
:
(
NSLayoutManager
*)
layoutManager
{
ASTextKitComponents *components = [[
self
alloc
]
init
];
components.
textStorage
= textStorage;
components.
layoutManager
= layoutManager;
[components.textStorage
addLayoutManager:
components.layoutManager];
components.
textContainer
= [[
NSTextContainer
alloc
]
initWithSize:
textContainerSize];
components.
textContainer
.
lineFragmentPadding
=
0.0
;
//
We want the text laid out up to the very edges of the text-view.
[components.layoutManager
addTextContainer:
components.textContainer];
return
components;
}
- (CGSize)
sizeForConstrainedWidth
:
(CGFloat)
constrainedWidth
{
ASTextKitComponents *components = self;
//
If our text-view's width is already the constrained width, we can use our existing TextKit stack for this sizing calculation.
//
Otherwise, we create a temporary stack to size for `constrainedWidth`.
if
(
CGRectGetWidth
(components.
textView
.
bounds
) != constrainedWidth) {
components = [ASTextKitComponents
componentsWithAttributedSeedString:
components.textStorage
textContainerSize:
CGSizeMake
(constrainedWidth,
FLT_MAX
)];
}
//
Force glyph generation and layout, which may not have happened yet (and isn't triggered by -usedRectForTextContainer:).
[components.layoutManager
ensureLayoutForTextContainer:
components.textContainer];
CGSize textSize = [components.layoutManager
usedRectForTextContainer:
components.textContainer].
size
;
return
textSize;
}
@end
Back
|
FazBrowse Home
|
New Git URL