我有一個方法接受一個UIBezierPath作爲參數並相應地繪製一個形狀。如果我使用純色填充圖形,渲染效果會很好,但如果嘗試使其具有Alpha透明色,我首先會收到ARC警告,要求更改代碼並使用橋接,然後填充顏色根本不渲染。CAShapeLayer fillColor不呈現
這工作,但不是我想要的:
standShapeLayer.fillColor = [[UIColor redColor] CGColor];
這產生電弧警告「到C指針CGColorRef目標C指針類型的UIColor的隱式轉換」。
standShapeLayer.fillColor = [UIColor colorWithRed:0.2 green:0.66 blue:0.86 alpha:2.0f];
此運行,但沒有填充顏色應用於形狀:
standShapeLayer.fillColor = (__bridge CGColorRef)([UIColor colorWithRed:0.2 green:0.66 blue:0.86 alpha:2.0f]);
下面是該方法的整個代碼:
-(void)drawShape:(UIBezierPath *)standShape {
[standShapeLayer removeFromSuperlayer];
selectedStand = standShape;
standShapeLayer = [CAShapeLayer layer];
standShapeLayer.path = standShape.CGPath;
standShapeLayer.fillColor = (__bridge CGColorRef)([UIColor colorWithRed:0.2 green:0.66 blue:0.86 alpha:2.0f]);
NSLog(@"color = %@", standShapeLayer.fillColor); // This logs the correct colour which is not rendered.
// standShapeLayer.fillColor = [[UIColor redColor] CGColor]; << This works but is not what I need.
standShapeLayer.strokeColor = [[UIColor redColor] CGColor];
standShapeLayer.lineWidth = 2;
[_imageView.layer addSublayer:standShapeLayer];
}
什麼我需要怎樣做才能讓顏色用alpha來填充CAShapeLayer形狀?
雖然你可能是正確的,仍然呈現爲我的阿爾法水平在1.0以上的顏色。對於我來說,問題是通過添加'CGColor'來填充color屬性來解決的。 – Ryan
如果它有用,你仍然可以upvote我的答案:) – Avt