views:

38

answers:

2

I have a UIImageView that is being rounded on my custom drawn UITableViewCell:

        rect = CGRectMake(13, 10, 48, 48);
        avatar = [[UIImageView alloc] initWithFrame:rect];
        [self.contentView addSubview: avatar];

        CALayer * l = [avatar layer];
        [l setMasksToBounds:YES];
        [l setCornerRadius:9.0];

I noticed my UITableView scrolling performance decreased a little bit. Not sure if it is related to the rounded corners though?

A: 

It shouldn't. Every UIView is backed by a CAlayer. You're not making anything new.

I don't know much about how the rounded corners work, but I'd imagine the rendering has to be more difficult than a rectangular layer.(You should take a hit either way, whether it does it through compositing or a nonstandard draw 'rectangle').

anq
+1  A: 

Rounded corners slow down drawing a lot. Mask layers are somewhat faster. "Baking" the corners into the content (as an image or using a clipping path in your drawRect:) is faster still.

Allocating new views/layers will also slow down your scrolling--reuse them wherever you can (creating a UITableViewCell subclass that creates the subviews in init and destroys them in dealloc generally works well)

That being said, adding additional views shouldn't reduce performance noticeably.

rpetrich
Should I make my CALayer a member variable and then release it in dealloc? Right now it isn't being released.
Sheehan Alam
If you use `[CALayer layer]`, you don't need to release it; it's already autoreleased.
rpetrich