11

I can't find a solution for my issue, so I hope some experts could help me.

I have tableview with lots of cells. For each cell I have an image view with rounded corners:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView *exampleView;

...
exampleView.layer.cornerRadius =   5.f;
exampleView.clipsToBounds = YES;   
[cell.contentView addSubview:exampleView];
...

}

Resulting in a big lack of scrolling performance issue - when using cornerRadius and clipsToBounds = YES, any alternative solutions? (The rounded corner image view contains pictures, and if the corner isn't set. The scrolling is smooth. So the problem is here)

EDIT #1: to clarify that I have already read other posts:

...
exampleView.frame = CGRectMake(5.0f,size.height-15.0f,30.0f,30.0f);
exampleView.layer.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5].CGColor;
exampleView.layer.cornerRadius = 5.0f;
exampleView.layer.borderWidth       =   0.3f;
exampleView.layer.borderColor       =   [UIColor blackColor].CGColor;
exampleView.layer.masksToBounds = NO;
exampleView.layer.shouldRasterize = YES;
//exampleView.clipsToBounds = NO;
[exampleView setImage: myImage ];

EDIT #2: It's like myImage is lapping over the rounded corner view. How do I make the image fit the rounded corner view correct? or am I missing something?

Neru-J
  • 1,623
  • 2
  • 23
  • 38
  • possible duplicate of [UITABLEVIEW comes to a crawl when adding a UIABEL with cornerRadius to each cell](http://stackoverflow.com/questions/2256314/uitableview-comes-to-a-crawl-when-adding-a-uiabel-with-cornerradius-to-each-cell) and [UILabel layer cornerRadius negatively impacting performance](http://stackoverflow.com/questions/4735623/) – Jano Sep 02 '12 at 13:20
  • 1
    I have read them, and it didn't helped me out. – Neru-J Sep 02 '12 at 13:24
  • Really, because you won't get any different answers. Either use a rounded image in the first place or render a rounded image yourself and use that. Is it the same image every time, or a different one? – jrturton Sep 02 '12 at 13:30
  • See my edit. Your first suggestion is overkill here. The second: Is it the correct way to make my rounded image? – Neru-J Sep 02 '12 at 13:33
  • It's like myImage is lapping over the rounded corner view. How do I make the image fit the rounded corner view correct? – Neru-J Sep 02 '12 at 14:02
  • @Jano See the accepted answer. This issue differs from the label examples !!! – Neru-J Sep 02 '12 at 17:07

1 Answers1

10

Just change the following line

  exampleView.layer.masksToBounds = YES;

To round out the corners in your imageView. See images below.

The tableview scrolling is a issue with view compositing. In addition to suggestions above, this will certainly help - Set the opaque property of the UITableViewCell's contentView property, and backgroundView property. Go:

  [cell.contentView setOpaque:YES];
  [cell.backgroundView setOpaque:YES];

This will help reduce the view compositing effort at the earliest possible stage.

There are additional, advanced, techniques which would require you to use asynchronous processing to process your images as you scroll. They may be overkill if the above techniques work.

UIImageView with the layer's maskToBounds set to yes UIImageView with the layer's maskToBounds set to No

clearwater82
  • 1,746
  • 14
  • 9
  • Finally, you saved my day. I was pulling hair out today heh. Thank you so much. It works like a charm! :) – Neru-J Sep 02 '12 at 17:04