17
17
18
18
@interface UIBubbleTableViewCell ()
19
19
- (void ) setupInternalData ;
20
+ @property (nonatomic , retain ) UIView *oldCustomView;
20
21
@end
21
22
22
23
@implementation UIBubbleTableViewCell
23
24
24
25
@synthesize dataInternal = _dataInternal;
26
+ @synthesize oldCustomView = _oldCustomView;
25
27
26
28
- (void )setFrame : (CGRect)frame
27
29
{
@@ -33,6 +35,8 @@ - (void) dealloc
33
35
{
34
36
[_dataInternal release ];
35
37
_dataInternal = nil ;
38
+ [_oldCustomView release ];
39
+ _oldCustomView = nil ;
36
40
[super dealloc ];
37
41
}
38
42
@@ -58,22 +62,39 @@ - (void) setupInternalData
58
62
}
59
63
60
64
NSBubbleType type = self.dataInternal .data .type ;
65
+ CGFloat imageOffsetX = 5.0 ;
66
+ CGFloat imageOffsetY = 6.0 ;
61
67
62
- float x = (type == BubbleTypeSomeoneElse) ? 20 : self.frame .size .width - 20 - self.dataInternal .labelSize .width ;
68
+ CGFloat height = self.dataInternal .data .view ? (CGRectGetHeight (self.dataInternal .data .view .frame ) + imageOffsetY*2.0 ) : self.dataInternal .labelSize .height ;
69
+ CGFloat width = self.dataInternal .data .view ? (CGRectGetWidth (self.dataInternal .data .view .frame ) + imageOffsetX*2.0 ) : self.dataInternal .labelSize .width ;
70
+
71
+ float x = (type == BubbleTypeSomeoneElse) ? 20 : self.frame .size .width - 20 - width;
63
72
float y = 5 + (self.dataInternal .header ? 30 : 0 );
64
73
65
- contentLabel.font = [UIFont systemFontOfSize: [UIFont systemFontSize ]];
66
- contentLabel.frame = CGRectMake (x, y, self.dataInternal .labelSize .width , self.dataInternal .labelSize .height );
67
- contentLabel.text = self.dataInternal .data .text ;
68
-
74
+ [self .oldCustomView removeFromSuperview ];
75
+ self.oldCustomView = nil ;
76
+
77
+ if (!self.dataInternal .data .view ) {
78
+ contentLabel.hidden = NO ;
79
+ contentLabel.font = [UIFont systemFontOfSize: [UIFont systemFontSize ]];
80
+ contentLabel.frame = CGRectMake (x, y, self.dataInternal .labelSize .width , self.dataInternal .labelSize .height );
81
+ contentLabel.text = self.dataInternal .data .text ;
82
+ }
83
+ else
84
+ {
85
+ contentLabel.hidden = YES ;
86
+ self.oldCustomView = self.dataInternal .data .view ;
87
+ [self .contentView addSubview: self .oldCustomView];
88
+ self.oldCustomView .frame = CGRectMake (x+imageOffsetX-1.0 , y+imageOffsetY+3.0 , CGRectGetWidth (self.oldCustomView .frame ), CGRectGetHeight (self.oldCustomView .frame ));
89
+ }
69
90
if (type == BubbleTypeSomeoneElse)
70
91
{
71
92
bubbleImage.image = [[UIImage imageNamed: @" bubbleSomeone.png" ] stretchableImageWithLeftCapWidth: 21 topCapHeight: 14 ];
72
- bubbleImage.frame = CGRectMake (x - 18 , y - 4 , self. dataInternal . labelSize . width + 30 , self. dataInternal . labelSize . height + 15 );
93
+ bubbleImage.frame = CGRectMake (x - 18 , y - 4 , width + 30 , height + 15 );
73
94
}
74
95
else {
75
96
bubbleImage.image = [[UIImage imageNamed: @" bubbleMine.png" ] stretchableImageWithLeftCapWidth: 15 topCapHeight: 14 ];
76
- bubbleImage.frame = CGRectMake (x - 9 , y - 4 , self. dataInternal . labelSize . width + 26 , self. dataInternal . labelSize . height + 15 );
97
+ bubbleImage.frame = CGRectMake (x - 9 , y - 4 , width + 26 , height + 15 );
77
98
}
78
99
}
79
100
0 commit comments