2017-09-20 1 views
0

複数の色のセグメントでリングを作成しています。iOS - 複数のサブレイヤを追加した後に背景が黒く表示される

CGFloat viewWidth = rect.size.width; 
CGFloat viewHeight = rect.size.height; 
CGFloat lineWidth = viewWidth * 0.15f; 
CGFloat radius = viewWidth/2 - lineWidth; 

CGPoint center = CGPointMake(viewWidth/2, viewHeight/2); 

UIColor *lavender = [UIColor colorWithRed:0.5f green:0.0f blue:1.0f alpha:1.0f]; 
UIColor *purple = [UIColor purpleColor]; 
UIColor *fuchsia = [UIColor colorWithRed:1.0 green:0.0f blue:0.5f alpha:1.0f]; 
UIColor *red = [UIColor redColor]; 
UIColor *orange = [UIColor orangeColor]; 
UIColor *yellow = [UIColor yellowColor]; 
UIColor *yellowGreen = [UIColor colorWithRed:0.5f green:1.0f blue:0.0f alpha:1.0f]; 
UIColor *green = [UIColor greenColor]; 
UIColor *blueGreen = [UIColor colorWithRed:0.0f green:1.0f blue:0.5f alpha:1.0f]; 
UIColor *cyan = [UIColor cyanColor]; 
UIColor *white = [UIColor whiteColor]; 
UIColor *lightBlue = [UIColor colorWithRed:0.0f green:0.5f blue:1.0f alpha:1.0f]; 
UIColor *blue = [UIColor blueColor]; 

NSArray *colors = @[lavender, purple, fuchsia, 
        red, orange, yellow, 
        yellowGreen, green, blueGreen, 
        cyan, white, lightBlue, blue]; 

for(int i = 0; i < 13; i++) 
{ 
    CGFloat startAngle = 0.1538f * M_PI * i; 
    CGFloat endAngle = 0.1538f * M_PI * (i + 1); 

    UIColor *strokeColor = [colors objectAtIndex:i]; 

    UIBezierPath *bezierPath = [UIBezierPath bezierPath]; 
    [bezierPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES]; 

    CAShapeLayer *colorPieceLayer = [[CAShapeLayer alloc] init]; 
    [colorPieceLayer setPath:bezierPath.CGPath]; 
    [colorPieceLayer setStrokeColor:strokeColor.CGColor]; 
    [colorPieceLayer setFillColor:[UIColor clearColor].CGColor]; 
    [colorPieceLayer setLineWidth:lineWidth]; 

    [self.layer addSublayer:colorPieceLayer]; 
} 

私が試した:

  1. サブレイヤcolorPieceLayer.backgroundColor = [UIColor clearColor].CGColorの背景色を設定する層self.layer.backgroundColor = [UIColor clearColor].CGColor
  2. の背景色を設定するビューself.backgroundColor = [UIColor clearColor];
  3. の背景色を設定する。ここに私のコードです
  4. 不透明度を設定します(ただし、これによってビューが消えます)。

は、ここに私のスクリーンショットです:

enter image description here

は、ここに私のビュー層です:

enter image description here

それでは、どのように私はそれクリアカラーにするつもりです????

NOTEをご利用ください:

紫色のは、私のカラーリングビューを保持しているだけのUIViewです。だから、

答えて

0

私はビューの背景色を変更する、この色を変更しました。

あなたはそれを試みることができます。

enter image description here

enter image description here

関連する問題