IOS / Objective-C:矩形的圆顶角,没有擦除边框

时间:2017-11-08 17:49:19

标签: ios objective-c uitextfield rounded-corners

我使用以下方法对uitextfield的特定角进行舍入。但是,它具有擦除圆角处边框的效果。任何人都可以建议这样做而不擦除边框?提前感谢任何建议。

-(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 个答案:

答案 0 :(得分:0)

你试过这个吗?给角部半径以达到该部分。例如:

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

答案 1 :(得分:0)

这样做的一种可能方法是重绘边框。正如

-(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 = self.imageView.bounds;
    borderShape.path = path.CGPath;
    borderShape.strokeColor = [UIColor blackColor].CGColor;
    borderShape.fillColor = nil;
    borderShape.lineWidth = 3;
    [view.layer addSublayer:borderShape];
}

希望这会有所帮助。 Referred from this SO Post