Reputation: 3404
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?
Upvotes: 16
Views: 7974
Reputation: 969
I hit the some problem, and I solved this confused problem by an ugly way finally.
// Create a subclass of UITableView
// Then override setClipsToBounds:
- (void)setClipsToBounds:(BOOL)clipsToBounds {
[super setClipsToBounds:YES];
}
Upvotes: 2
Reputation: 23400
In iOS 8, checking the cell's "Clip Subviews" in the XIB did not work.
What does work is:
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.clipsToBounds = YES;
}
Upvotes: 1
Reputation: 4507
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.
Upvotes: 2
Reputation: 57050
As discussed in the comments, the only solution right now in iOS7.1 is to set clipsToBounds
on the cell itself.
Upvotes: 10