Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot set clipToBounds on UITableViewCell's contentView in iOS 7.1

The iOS 7 redesign resulted in change of the view hierarchy of UITableViewCells. The content view of the cell was wrapped in a private class called UITableViewCellScrollView.

In iOS 7 UITableViewCellScrollView has clipsToBounds set to YES and UITableViewCellContentView has clipToBounds set to NO.

In iOS 7.1 UITableViewCellScrollView has clipsToBounds set to NO and UITableViewCellContentView has clipToBounds set to NO.

If you call [[self contentView] setClipsToBounds:YES] in iOS 7.1 is does it stick. By the time layoutSubviews is called on the cell UITableViewCellContentView has clipToBounds set to NO again.

[[self contentView] superview] setClipsToBounds:YES] works in iOS 7.1 and sets UITableViewCellScrollView's clipToBounds to YES but this is a very brittle solution.

Overriding layoutSubview on the cell and calling [[self contentView] setClipsToBounds:YES] works but is another fraile solution.

Does anyone know why this change has been made and a more robust solution to it?

like image 751
Reid Main Avatar asked Mar 13 '14 18:03

Reid Main


2 Answers

As discussed in the comments, the only solution right now in iOS7.1 is to set clipsToBounds on the cell itself.

like image 121
Léo Natan Avatar answered Nov 03 '22 00:11

Léo Natan


It's quite annoying. What I did is add an UIView in the contentView with identical size (and autoresizingMask in width), add the relevant content to this view, and set clipsToBounds to it.

like image 26
Eino Gourdin Avatar answered Nov 02 '22 23:11

Eino Gourdin