CATextLayer:未显示文本

时间:2016-09-26 03:27:13

标签: ios objective-c catextlayer

当我尝试将图像添加为CATextLayer内容时,不会显示文本。仅显示图像。这是我在viewDidLoad()方法中放置的代码,

    UIImage *uiimage = [UIImage imageNamed:@"flying.png"];
    CATextLayer *textLayer = [CATextLayer layer];
    textLayer.frame = CGRectMake(144, 42, 76, 21);
    textLayer.font = CFBridgingRetain([UIFont boldSystemFontOfSize:18].fontName);
    textLayer.fontSize = 18;
    textLayer.foregroundColor = [UIColor redColor].CGColor;
    textLayer.backgroundColor = [UIColor yellowColor].CGColor;
    textLayer.alignmentMode = kCAAlignmentCenter;
    textLayer.string = @"Hello world";
    textLayer.contents = (id)uiimage.CGImage;
    [self.view.layer addSublayer:textLayer];

请帮助解决问题。

0 个答案:

没有答案