Jorge
Jorge

Reputation: 1532

Subviews gets trimmed when out of UITableViewCell bounds

I've been looking around and can't find a solution to my problem. I have a UIImageView as subview of UITableViewCell, I add it in cellForRowAtIndexPath, the frame of subview starts on cell-1 and goes out of cell-1, getting into cell-2.

Basically, I want my image to be on the middle of two cells. Now, when tableViewfirst loads, it appears correctly, but when I scroll the cells down and go back, the image is trimmed, showing only the part that is in cell-1 bounds.

I know iOS 7 has a scrollView between contentView and cell. When I log on my cellForRowAtIndexPath:

if (cell.contentView.superview.clipsToBounds == YES || cell.contentView.clipsToBounds == YES || cell.clipsToBounds == YES) {
    NSLog(@"CLIP = YES");
} else {
    NSLog(@"CLIP = NO");
}

it shows me that cell, contentView and scrollView have the property clipToBounds set to NO, which is what I want.

I just don't know why subviews still get trimmed.

Upvotes: 0

Views: 416

Answers (1)

duci9y
duci9y

Reputation: 4168

I ran across the same problem as you.

I realised that the problem was my cell had non-transparent backgrounds. The subviews weren't being clipped, they were simply getting covered by the background colours of previously added cells.

You can't control the order in which cells get added to the table view, so you'd have to use [UIColor clearColor] as the background colour of your cells to get the desired effect.

If that's an issue, set the zPosition of your subview to a high enough number and you'd hopefully be good to go.

Upvotes: 1

Related Questions