title: Using UIImageView's with [UIImage resizableImageWithCapInsets] in a UITableView causes lag
body: <p>Here is the code I'm using to generate the UITableViewCell. I'm testing in iOS6/iOS7. If I remove the code about the UIImageView the UITableView scrolls just fine. But with the UIImageView it lags and spasms. I'm looking for some solution to fix the lagging. Thank you in advance.</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          static NSString *CellIdentifier = @"BubbleCell";
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
          UILabel *label;
          UIImageView *bubbleLeft;
          UIImageView *bubbleRight;
  
          if(cell == nil)
          {
          cell = [[
      UITableViewCell
      alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
  
              label = [[UILabel alloc] init];
              label.tag = 1;
  
              NSString *fileLeft = [[NSBundle mainBundle] pathForResource:@"chatBubbleGray.png" ofType:nil];
              NSString *fileRight = [[NSBundle mainBundle] pathForResource:@"chatBubbleBlue.png" ofType:nil];
  
      UIImage
      *bubbleImageLeft = [[
      UIImage imageWithContentsOfFile:fileLeft] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 22, 20, 22)];
  
      UIImage
      *bubbleImageRight = [[
      UIImage imageWithContentsOfFile:fileRight] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 22, 20, 22)];
  
              bubbleLeft = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 10, 10)];
              [bubbleLeft setImage:bubbleImageLeft];
              bubbleLeft.tag=2;
              bubbleRight = [[UIImageView alloc] initWithFrame:CGRectMake(320 - 20, 10, 10, 10)];
              [bubbleRight setImage:bubbleImageRight];
              bubbleRight.tag=3;
  
              [cell addSubview:bubbleLeft];
              [cell addSubview:bubbleRight];
              [cell addSubview:label];
  
          }else{
              label = (UILabel *)[cell viewWithTag:1];
              bubbleLeft = (UIImageView *)[cell viewWithTag:2];
              bubbleRight = (UIImageView *)[cell viewWithTag:3];
          }
  
  
      // set frame to largest size you want
  
          label.numberOfLines = 0;
          label.
      backgroundColor = [UIColor clearColor];
          label.
      text
      = [[[
      currentDictionary objectAtIndex:indexPath.row] objectForKey:@"string"] stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
  
          CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX);
  
          CGSize expectedLabelSize = [label.text sizeWithFont:label.font constrainedToSize:maximumLabelSize lineBreakMode:label.lineBreakMode];
  
          if (indexPath.row%2==0) {
              bubbleRight.hidden = YES;
              bubbleLeft.hidden = NO;
              bubbleLeft.frame = CGRectMake(10, 10, expectedLabelSize.width+20, expectedLabelSize.height+20);
  
              label.frame = CGRectMake(
                                       20, 20,
                                       expectedLabelSize.width, expectedLabelSize.height);
  
          }else{
              bubbleLeft.hidden = YES;
              bubbleRight.hidden = NO;
  
              bubbleRight.frame = CGRectMake(320 - expectedLabelSize.width - 30, 10, expectedLabelSize.width+20, expectedLabelSize.height+20);
  
              label.frame = CGRectMake(
                                       320 - expectedLabelSize.width - 20, 20,
                                       expectedLabelSize.width, expectedLabelSize.height);
          }
  
  
  
      // Configure the cell...
  
          return cell;
      }
  </code></pre>
  
  <p><strong><em>EDIT:</em></strong></p>
  
  <p>Further reviewing the code showed that the lagging is actually caused by this piece of code:
  <code>bubbleLeft.frame = CGRectMake(10, 10, expectedLabelSize.width+20, expectedLabelSize.height+20);</code></p>