Burhanuddin Sunelwala
Burhanuddin Sunelwala

Reputation: 5343

UITableViewCell clipsToBound not working

enter image description here

In my custom cell I have written [self setClipsToBound : YES] and then adding these red imageViews as its subviews as [self addSubview:imageView]

But as you can see the imageView is not getting clipped.

I searched, but din't find any success!

Upvotes: 2

Views: 924

Answers (2)

danypata
danypata

Reputation: 10175

Yes, the problem is your grouped tableView, is very unintuitive the fact that a grouped table view cell has the same width as a normal table view, the only difference is that a grouped table view has a different cell background (also for selected state) and margins for the content of the cell which are created by a different position of the cells labels.

You should create assets with top right and bottom right corners rounded (for first cell and last cell from a section). The clipSubview won't work for your case because the imageView dosen't rich out of the cells content.

Upvotes: 1

Mark McCorkle
Mark McCorkle

Reputation: 9414

Use the following code to add an image to the background of a grouped cell.

UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, yourCell.frame.size.width, 80)]; // Modify this for your cell
imgView.contentMode = UIViewContentModeScaleAspectFit;
cell.backgroundColor = [UIColor colorWithPatternImage:imgView.image];

Upvotes: 1

Related Questions