3

I am using the following method to round specific corners of uitextfield. However, it has the effect of erasing the border at the rounded corner. Can anyone suggest way to do this without erasing border? Thanks in advance for any suggestions.

-(void)roundBottomCornersOfView: (UITextField*) view by: (NSInteger) radius {
    CGRect rect = view.bounds;
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect
                                               byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight
                                                     cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer *layers = [CAShapeLayer layer];
    layers.frame = rect;
    layers.path = path.CGPath;
    view.layer.mask = layers;
}

enter image description here

2 Answers 2

2

One possible way of doing this could be to redraw your border. As

-(void)roundBottomCornersOfView: (UITextField*) view by: (NSInteger) radius {
    CGRect rect = view.bounds;
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect
                         byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight
                         cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer *layers = [CAShapeLayer layer];
    layers.frame = rect;
    layers.path = path.CGPath;
    view.layer.mask = layers;

    CAShapeLayer*   borderShape = [CAShapeLayer layer];
    borderShape.frame = rect;
    borderShape.path = path.CGPath;
    borderShape.strokeColor = [UIColor blackColor].CGColor;
    borderShape.fillColor = nil;
    borderShape.lineWidth = 3;
    [view.layer addSublayer:borderShape];
}

Hope this helps. Referred from this SO Post

Sign up to request clarification or add additional context in comments.

Comments

-1

Have you tried this? Give some corner radius to achieve that part. Example:

nameOfTextField.layer.cornerRadius = 15.0
nameOfTextField.layer.borderWidth = 2.0 // Use border width if you need it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.