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?

6

1 Answer 1

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

1
  • Finally, you saved my day. I was pulling hair out today heh. Thank you so much. It works like a charm! :)
    – Neru-J
    Sep 2, 2012 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.