CALayer顶部的CATextLayer?

时间:2012-08-10 23:26:02

标签: ios calayer catextlayer

我正在尝试使用zPosition将此CATextLayer置于我的CALayer之上,但CATextLayer似乎总是落后于CALayer?

CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor colorWithRed:0/255.0 green:156.0/255.0 blue:222.0/255.0 alpha:1.0].CGColor;
sublayer.shadowOffset = CGSizeMake(0, 3);
sublayer.shadowRadius = 5.0;
sublayer.shadowColor = [UIColor blackColor].CGColor;
sublayer.shadowOpacity = 0.8;
sublayer.frame = CGRectMake(340, 435, 126, 1);
sublayer.zPosition=1;
[self.view.layer addSublayer:sublayer];
CGSize size=CGSizeMake(126, 265);
[self resizeLayer:sublayer to:size];



CATextLayer *label = [[CATextLayer alloc] init];
[label setFont:@"Helvetica-Neue"];
[label setFontSize:56];  
[label setFrame: self.view.frame];
[label setString:@"56"];
[label setAlignmentMode:kCAAlignmentCenter];
[label setForegroundColor:[[UIColor whiteColor] CGColor]];
label.zPosition=99;
[self.view.layer  addSublayer:label];

1 个答案:

答案 0 :(得分:0)

> CATextLayer *label = [[CATextLayer alloc] init];
> [label setFont:@"Helvetica-Neue"];
> [label setFontSize:56];  
> [label setFrame: self.view.frame];
> [label setString:@"56"];
> [label setAlignmentMode:kCAAlignmentCenter];
> [label setForegroundColor:[[UIColor whiteColor] CGColor]];
> label.zPosition=99;
> [self.view.layer  addSublayer:label];

我会改变:

[self.view.layer  addSublayer:label];

要:

[self.view.layer insertSublayer:label Above:sublayer];