0
我已經生成了一個包含CAShapeLayer
的圓圈,現在正試圖通過CATextLayer
在其上添加一個標籤,但它並未顯示出來。我不知道我錯過了什麼?在CAShapeLayer上添加文本
CAShapeLayer *circleLayer = [CAShapeLayer layer];
[circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(carouselView.frame.size.width - 42, addCardButton.frame.origin.y - 5, 20, 20)] CGPath]];
[circleLayer setStrokeColor:[[UIColor whiteColor] CGColor]];
[circleLayer setFillColor:[[UIColor redColor] CGColor]];
CATextLayer* text = [CATextLayer new];
text.string = @"1";
text.fontSize = 25;
text.frame = CGRectMake(0,0,60,60);
text.position = CGPointMake(CGRectGetMidX(circleLayer.frame) ,CGRectGetMidY(circleLayer.frame));
CGFloat vert = CGRectGetMidY(circleLayer.frame)/CGRectGetHeight(text.frame);
text.anchorPoint = CGPointMake(0.5, vert);
text.alignmentMode = kCAAlignmentCenter;
text.foregroundColor = [[UIColor blackColor] CGColor];
[circleLayer addSublayer:text];
[[carouselView layer] addSublayer:circleLayer];