| 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
|
#import "UILabelWrap.h"
@implementation UILabelWrap
@synthesize text, font, color, highlightedTextColor, textColor=color, shadowColor, shadowOffset;
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
}
return self;
}
- (void)setText:(NSString*)newText {
if([newText isEqualToString:text]) return;
if(text) [text release];
text = [newText copy];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
if(!self.text) return;
if(!isHighlighted && self.shadowColor) {
[self.shadowColor set];
CGRect offsetRect = rect;
offsetRect.origin = CGPointMake(offsetRect.origin.x+self.shadowOffset.width, offsetRect.origin.y+self.shadowOffset.height);
[self.text drawInRect:offsetRect withFont:self.font lineBreakMode:UILineBreakModeWordWrap|UILineBreakModeTailTruncation alignment:UITextAlignmentLeft];
}
if(isHighlighted) {
[self.highlightedTextColor set];
} else {
[self.color set];
}
[self.text drawInRect:rect withFont:self.font lineBreakMode:UILineBreakModeWordWrap|UILineBreakModeTailTruncation alignment:UITextAlignmentLeft];
}
- (UIFont*)font {
if(!font) {
self.font = [UIFont systemFontOfSize:17.0f];
}
return font;
}
- (UIColor*)color {
if(!color) {
self.color = [UIColor blackColor];
}
return color;
}
- (UIColor*)highlightedTextColor {
if(!highlightedTextColor) {
self.highlightedTextColor = [UIColor whiteColor];
}
return highlightedTextColor;
}
- (void)setHighlighted:(BOOL)highlighted {
isHighlighted = highlighted;
[self setNeedsDisplay];
}
- (BOOL)isHighlighted {
return isHighlighted;
}
- (void)setFrame:(CGRect)frame {
[super setFrame:frame];
[self setNeedsDisplay];
}
- (void)dealloc {
if(text) [text release];
if(font) [font release];
if(color) [color release];
if(highlightedTextColor) [highlightedTextColor release];
if(shadowColor) [shadowColor release];
[super dealloc];
}
@end
|