-
Notifications
You must be signed in to change notification settings - Fork 1
/
TLDrawnText.h
85 lines (71 loc) · 3.1 KB
/
TLDrawnText.h
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
//
// TLDrawnText.h
// TLCommon
//
// Created by Joshua Bleecher Snyder on 10/14/09.
//
#import <Foundation/Foundation.h>
@interface TLDrawnText : NSObject {
@private
// basic rendering parameters
NSString *text;
UIFont *font;
UILineBreakMode lineBreakMode;
UITextAlignment textAlignment;
UIColor *textColor;
// padding -- external
CGFloat minimumTopPadding;
BOOL flexibleTopPadding;
CGFloat minimumBottomPadding;
BOOL flexibleBottomPadding;
// insets -- internal
// these are used internally to calculate sizes and render
CGFloat leftInset;
CGFloat rightInset;
// calculated properties
CGRect renderRect; // includes insets
}
+ (TLDrawnText *)drawnText;
// the caller of this function should ignore any insets --
// they should pass the total width of the space available for text (including the insets)
// and will get back the total size of the space used for text (including the insets)
- (CGSize)sizeWithWidth:(CGFloat)totalWidthIncludingSpaceForInsets;
// the caller of this function should ignore any insets --
// they will be handled internally. they should set the render rect to include
// the total width of the space available for text (including the insets)
// this uses the renderRect to decide where to render.
//
// Returns the actual rect containing just the rendered text,
// including insets, text alignment, etc.
//
// KNOWN ISSUE: Returned rect is only fully accurate for UITextAlignmentLeft.
- (CGRect)render;
// sets the renderRect for a number of texts, according to their drawn text sizes and
// preferred padding. variadic to avoid requiring nsarray construction.
// it is expected that these are called w/in the render section of a tableviewcell
// and thus should not allocate space on the heap. with a careful
// use of static TLDrawnTexts, the entire rendering process should be able to take
// place solely with stack storage.
//
// The resulting renderRects are as wide as the containingRect. The actual location
// of the drawn text, including insets and text alignment, is returned from -render.
//
// Returns the total height of the laid out text and buffers.
+ (CGFloat)layoutInRect:(CGRect)containingRect
canOverflowBottomOfRect:(BOOL)rectCanBeMadeBigger
texts:(TLDrawnText *)firstText, ... NS_REQUIRES_NIL_TERMINATION;
// self.renderRect but adjusted for text insets
- (CGRect)insetAdjustedRenderRect;
@property(nonatomic, retain, readwrite) NSString *text;
@property(nonatomic, retain, readwrite) UIFont *font;
@property(nonatomic, assign, readwrite) UILineBreakMode lineBreakMode;
@property(nonatomic, assign, readwrite) UITextAlignment textAlignment;
@property(nonatomic, retain, readwrite) UIColor *textColor;
@property(nonatomic, assign, readwrite) CGFloat minimumTopPadding;
@property(nonatomic, assign, readwrite) BOOL flexibleTopPadding;
@property(nonatomic, assign, readwrite) CGFloat minimumBottomPadding;
@property(nonatomic, assign, readwrite) BOOL flexibleBottomPadding;
@property(nonatomic, assign, readwrite) CGFloat leftInset;
@property(nonatomic, assign, readwrite) CGFloat rightInset;
@property(nonatomic, assign, readwrite) CGRect renderRect;
@end