0

I'm creating UIItableview. For the first cell I want to have a user Image with a button to allow him to change the image. (not so complicated). Somehow I have a strange problem: When I set setMasksToBounds:NO the [self.userTable.layer setCornerRadius:20.0]; is simply get disabled. I am attaching a code with output example:

//Initiate UserTable
//[self.userTable setClipsToBounds:NO];//from the documentation this line is set by default
[self.userTable.layer setCornerRadius:20.0];
[self.view addSubview:self.userTable];

later in cellForRowAtIndexPath: I add:

[myCellView.contentView addSubview:photo]; //My photo is UImageview

enter image description here

If I uncomment the line [self.userTable setClipsToBounds:NO] I get: enter image description here

but my corners are not rounded any more...... I read the following questions this and this and still cant figure that out? Did someone had this problem and can provide a fix which will not force me to change all my code? and also how the 2 options are related to each other? Thanks a lot.

Community
  • 1
  • 1
Mike.R
  • 2,824
  • 2
  • 26
  • 34
  • That's how `cornerRadius` works - by masking to a rounded corner. How did _you_ think it worked? – matt Apr 20 '14 at 20:05

1 Answers1

2

Calling setCornerRadius applies a mask to your CALayer, which is then used to mask the bounds and create the rounded corner effect. By calling setMasksToBounds:NO, you are disabling the mechanism used to round the corners.

In short, you can't have it both ways.

Consider making that row in the tableview taller, or using a custom view instead of a standard UITableViewCell.

Nick
  • 2,361
  • 16
  • 27
  • Tnx Nick, you are right. In the end I put a background view with round corners. I wonder why Apple documentations says clipsToBounds is default NO?(its look like the other way around). – Mike.R Apr 21 '14 at 10:03