【发布时间】:2018-01-08 04:33:13
【问题描述】:
我有一个贝塞尔路径,我将其转换为 CALayer,然后添加到视图中。
我希望 UIView 的高度和宽度与 CALayer 形状完全一致。
myHTML = @"<html><body><svg height= \"400\" width= \"400\"><g><path d=\"M 20 20 C 30 30 40 40 50 50 M 50 50 C 60 70 80 70 60 50 \" transform=\"translate(-20, -20)\" stroke = \"#000000\" fill=\"none\" stroke-width=\"5px\"></path></g></svg></body></html>";
NSArray *test = [SVGBezierPath pathsFromSVGString:myHTML];
for(SVGBezierPath *path in test) {
// Create a layer for each path
CAShapeLayer *layer = [CAShapeLayer layer];
layer.path = path.CGPath;
UIView *vw = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
// Set its display properties
layer.lineWidth = 4;
layer.strokeColor = [[UIColor blackColor] CGColor];
layer.fillColor = [[UIColor clearColor] CGColor];
vw.center = self.view.center;
[vw setBackgroundColor:[UIColor grayColor]];
// Add it to the layer hierarchy
[vw.layer addSublayer:layer];
[self.view addSubview:vw];
}
我试着给视图层的宽度和高度
vw = [[UIView alloc]initWithFrame:CGRectMake(vw.bounds.origin.x, vw.bounds.origin.y, layer.bounds.size.height, layer.bounds.size.width)];
然后视图消失,只有图层可见。
我想得到如下图所示的东西,我有调整大小视图和东西的代码,但需要让视图的边界恰好是视图的最大高度和最大宽度,如下所示。
【问题讨论】:
标签: objective-c uiview calayer uibezierpath