gpt4 book ai didi

ios - CATextLayer位于CALayer的顶部吗?

转载 作者:行者123 更新时间:2023-12-01 16:55:52 26 4
gpt4 key购买 nike

我正在尝试使用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];

最佳答案

> 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];

关于ios - CATextLayer位于CALayer的顶部吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11910491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com