设置圆角虚边

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

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容