ios 绘制线框_iOS 绘制虚线框
- (void)setUpDashedBox2:(UIView *)view{
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setBounds:view.bounds];
[shapeLayer setPosition:view.center];
[shapeLayer setFillColor:[[UIColor groupTableViewBackgroundColor] CGColor]];
// 設置虛線顏色為blackColor
[shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]];
// [shapeLayer setStrokeColor:[HMMainlColor CGColor]];
// 3.0f設置虛線的寬度
[shapeLayer setLineWidth:1.0f];
[shapeLayer setLineJoin:kCALineJoinRound];
// 3=線的寬度 1=每條線的間距
[shapeLayer setLineDashPattern:
[NSArray arrayWithObjects:[NSNumber numberWithInt:5],
[NSNumber numberWithInt:3],nil]];
// Setup the path
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 3);
CGPathAddLineToPoint(path, NULL, 45,3);
CGPathMoveToPoint(path, NULL, 45, 3);
CGPathAddLineToPoint(path, NULL,45, 45);
CGPathMoveToPoint(path, NULL,45, 45);
CGPathAddLineToPoint(path, NULL, 0, 45);
CGPathMoveToPoint(path, NULL, 0, 45);
CGPathAddLineToPoint(path, NULL, 0, 3);
[shapeLayer setPath:path];
CGPathRelease(path);
[[view layer] addSublayer:shapeLayer];
}
只需要設置虛線框的四個坐標(左上( 0, 3)、右上( 45, 3)、右下( 45, 45)、左下( 0, 45))。
總結
以上是生活随笔為你收集整理的ios 绘制线框_iOS 绘制虚线框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: angularjs组件间通讯_详解Ang
- 下一篇: sklearn 相似度矩阵_精简易懂,3