Ответ 1
Установите цвет заливки на прозрачный (alpha 0)
[circleLayer setFillColor:[[UIColor colorWithWhite:0 alpha:0] CGColor]];
AKA...
[circleLayer setFillColor:[[UIColor clearColor] CGColor]];
(спасибо Зев)
Я использую этот код для рисования круга внутри 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 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 layer tree
[[photoView layer] addSublayer:circleLayer];
Я хотел бы, чтобы круг был пустым и имел только границу. Как удалить заполнение?
Установите цвет заливки на прозрачный (alpha 0)
[circleLayer setFillColor:[[UIColor colorWithWhite:0 alpha:0] CGColor]];
AKA...
[circleLayer setFillColor:[[UIColor clearColor] CGColor]];
(спасибо Зев)
На странице руководства CAShapeLayer явно указано, что set fillColor - nil
, чтобы выполнить операцию заполнения. Это не то же самое, что наполнить прозрачным цветом, что некоторые предложили сделать, поскольку последний перезапишет существующее содержимое, сделав его прозрачным/прозрачным, и его следует считать разрушительной.