【问题标题】:IOS/Objective-C: Round top corners of rectangle without erasing borderIOS / Objective-C:矩形的圆顶角不擦除边框
【发布时间】:2017-11-08 17:49:18
【问题描述】:

我正在使用以下方法来圆化 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;
}

【问题讨论】:

    标签: ios objective-c uitextfield rounded-corners


    【解决方案1】:

    这样做的一种可能方法是重新绘制边框。作为

    -(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];
    }
    

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

    【讨论】:

      【解决方案2】:

      你试过吗?给出一些圆角半径来实现该部分。示例:

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

      【讨论】:

        猜你喜欢
        • 2011-02-03
        • 1970-01-01
        • 1970-01-01
        • 2010-12-14
        • 2013-11-03
        • 2016-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多