美文网首页
设置圆角虚边

设置圆角虚边

作者: 呦嚯嚯嚯12138 | 来源:发表于2016-11-23 11:03 被阅读80次

    -(void)boundingRectangleForView:(UIView *)fatherView{

    CGRect frame = fatherView.bounds;

    CGFloat cornerRadius = 10.0f;

    CAShapeLayer *borderLayer = [CAShapeLayer layer];

    CGMutablePathRef path = CGPathCreateMutable();

    //drawing a border around a view

    CGPathMoveToPoint(path, NULL, 0, frame.size.height - cornerRadius);

    CGPathAddLineToPoint(path, NULL, 0, cornerRadius);

    CGPathAddArc(path, NULL, cornerRadius, cornerRadius, cornerRadius, M_PI, -M_PI_2, NO);

    CGPathAddLineToPoint(path, NULL, frame.size.width - cornerRadius, 0);

    CGPathAddArc(path, NULL, frame.size.width - cornerRadius, cornerRadius, cornerRadius, -M_PI_2, 0, NO);

    CGPathAddLineToPoint(path, NULL, frame.size.width, frame.size.height - cornerRadius);

    CGPathAddArc(path, NULL, frame.size.width - cornerRadius, frame.size.height - cornerRadius, cornerRadius, 0, M_PI_2, NO);

    CGPathAddLineToPoint(path, NULL, cornerRadius, frame.size.height);

    CGPathAddArc(path, NULL, cornerRadius, frame.size.height - cornerRadius, cornerRadius, M_PI_2, M_PI, NO);

    //path is set as the _shapeLayer object's path

    borderLayer.path = path;

    CGPathRelease(path);

    borderLayer.backgroundColor = [[UIColor clearColor] CGColor];

    borderLayer.frame = frame;

    borderLayer.masksToBounds = NO;

    [borderLayer setValue:[NSNumber numberWithBool:NO] forKey:@"isCircle"];

    borderLayer.fillColor = [[UIColor clearColor] CGColor];

    borderLayer.strokeColor = [[UIColor redColor] CGColor];

    borderLayer.lineWidth = 1;

    borderLayer.lineDashPattern =@[@4, @4];;

    borderLayer.lineCap = kCALineCapRound;

    [fatherView.layer addSublayer:borderLayer];

    fatherView.layer.cornerRadius = 10;

    }

    相关文章

      网友评论

          本文标题:设置圆角虚边

          本文链接:https://www.haomeiwen.com/subject/xhtvpttx.html