Reputation: 119
I want to make a chat bubble view in my project. And I stretched the image the be the bubble. But the issue happen, if I scroll the cell to be invisible, after the cell came back to original place the image can be stretched that's the only way to show the stretched image.
The following images are the brief description about issue.
The bubble view layouts in storyboard, UIImageView is the stretching image :
Before scroll:
After scroll:
When showing bubble view initially ( its original showing method: navigation bar item Segue), and call stretch function in viewWillAppear(), it display stretched normal.
The following is the key code: Initial bubble stretch in the cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
NSString *cellID = @"chatCell";
UIBubbleTableViewCell *cell = (UIBubbleTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
//CAll stretch function
cell.dataInternal = dataInternal;
}
The stretch function:
bubbleImage.image = [[UIImage imageNamed:@"chat2.png"] stretchableImageWithLeftCapWidth:21 topCapHeight:14];
bubbleImage.frame = CGRectMake(40, 10, 267, 105);
Call stretch function every updated :
- (void)viewDidAppear:(BOOL)animated{
[chatTable reloadData];
}
Anyway, only scrolling ended, the image could be displayed stretched. I debug the project, and log the stretch the stretch data, everything is well.
How could I fix the issue, thanks for any advise.
Upvotes: 1
Views: 677
Reputation: 11502
What you want to do is to put your image stretching function in the
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
delegate method. Only at this point will you know the actual size of the table cell to be displayed. Then you can stretch the bubble image to your heart's content.
Upvotes: 3