1717
1818@interface UIBubbleTableViewCell ()
1919- (void ) setupInternalData ;
20+ @property (nonatomic , retain ) UIView *oldCustomView;
2021@end
2122
2223@implementation UIBubbleTableViewCell
2324
2425@synthesize dataInternal = _dataInternal;
26+ @synthesize oldCustomView = _oldCustomView;
2527
2628- (void )setFrame : (CGRect)frame
2729{
@@ -33,6 +35,8 @@ - (void) dealloc
3335{
3436 [_dataInternal release ];
3537 _dataInternal = nil ;
38+ [_oldCustomView release ];
39+ _oldCustomView = nil ;
3640 [super dealloc ];
3741}
3842
@@ -58,22 +62,39 @@ - (void) setupInternalData
5862 }
5963
6064 NSBubbleType type = self.dataInternal .data .type ;
65+ CGFloat imageOffsetX = 5.0 ;
66+ CGFloat imageOffsetY = 6.0 ;
6167
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;
6372 float y = 5 + (self.dataInternal .header ? 30 : 0 );
6473
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+ }
6990 if (type == BubbleTypeSomeoneElse)
7091 {
7192 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 );
7394 }
7495 else {
7596 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 );
7798 }
7899}
79100
0 commit comments