Mason Mason - 15 days ago 5
iOS Question

CALayer inner border corner radius

I have a UITextView where I set the border width, border color, and corner radius properties on its layer, and the outside looks great. However, the inner part of the border doesn't have rounded corners like the outer part, and it looks kind of funny. Is there a way to round the inner corners of the border?

Edit:
Here's the code I used in the

initWithFrame:
method:

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = UIColorFromRGB(0xdedede);
self.layer.cornerRadius = kTextFieldCornerRadius;
self.layer.borderColor = UIColorFromRGB(0xD4974C).CGColor;
self.layer.borderWidth = 3.0f;
self.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:12.0f];
[self setClipsToBounds:YES];
[self.layer setMasksToBounds:YES];
}
return self;
}


And here's a screenshot of what it looks like now:

Notice the outer corners are rounded as expected, but the inner corners of the border are pointed rather than rounded. That's what I'm trying to fix. Thanks for your help!

Answer

Try to set this,

[txtView       setClipsToBounds:YES]; //Confirms subviews are confined to the bounds of the view
[txtView.layer setMasksToBounds:YES]; //Confirms sublayers are clipped to the layer’s bounds

EDIT

Probably the value of kTextFieldCornerRadius is set to low in your case.

If I set kTextFieldCornerRadius = 7; see I can get perfect output.

enter image description here

try to increase your radius value.

Comments