- (void)drawRect:(CGRect)rect{
// NSArray * layersArr = self.layer.sublayers;
// for( CATextLayer *textLayer in layersArr ){
// [textLayer removeFromSuperlayer];
// }
[[self layer] setSublayers:nil];
CATextLayer *textLayer = [CATextLayer layer];
textLayer.string = _attString;
textLayer.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
textLayer.contentsScale = 2;
[self.layer addSublayer:textLayer];
}
初期采用
// NSArray * layersArr = self.layer.sublayers;
// for( CATextLayer *textLayer in layersArr ){
// [textLayer removeFromSuperlayer];
// }
方式来解决,后面会出现崩溃。
最终采用:
[[self layer] setSublayers:nil];
的方式来解决。
网友评论