我正在使用此代码在UIImageView中绘制一个圆圈.
CAShapeLayer *circleLayer = [CAShapeLayer layer];
// Give the layer the same bounds as your image view
[circleLayer setBounds:CGRectMake(0.0f, 0.0f, [photoView bounds].size.width,
[photoView bounds].size.height)];
// Position the circle anywhere you like, but this will center it
// In the parent layer, which will be your image view's root layer
[circleLayer setPosition:CGPointMake(coordsFinal.x + 130, coordsFinal.y + 200)];
// Create a circle path.
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:
CGRectMake(0.0f, 0.0f, 50.0f, 50.0f)];
// Set the path on the layer
[circleLayer setPath:[path CGPath]];
// Set the stroke color
[circleLayer setStrokeColor:[color CGColor]];
// Set the stroke line width
[circleLayer setLineWidth:2.0f];
// Add the sublayer to the image view's layer tree
[[photoView layer] addSublayer:circleLayer];
Run Code Online (Sandbox Code Playgroud)
我希望圆圈是空的,只有边框.我怎样才能删除填充物?
fou*_*dry 18
将填充颜色设置为透明(alpha 0)
[circleLayer setFillColor:[[UIColor colorWithWhite:0 alpha:0] CGColor]];
Run Code Online (Sandbox Code Playgroud)
AKA ...
[circleLayer setFillColor:[[UIColor clearColor] CGColor]];
Run Code Online (Sandbox Code Playgroud)
(谢谢Zev)
CAShapeLayer 手册页明确说明将 fillColor 设置为nil不执行填充操作。这与填充透明颜色不同,有些人建议这样做,因为后者会覆盖现有内容,使它们变得清晰/透明,应该被视为一种破坏性操作。
| 归档时间: |
|
| 查看次数: |
11319 次 |
| 最近记录: |