3

I'm working on a video app that generates a credits clip using a .mov resource as the background and a CATextLayer for the credits. The code works in iOS 5 and 6, but not in iOS 7 - ie: the clip gets generated but text does not appear.

I've tried using the code from the answer to this question (How can I add overlay text on a video, then re-encode it?), but the text in the CATextLayer still does not show up.

Why is iOS 7 behaving differently and how can I get it to work?

Community
  • 1
  • 1
Rob VS
  • 682
  • 7
  • 11
  • I tried to solve it for 2 days and I couldn't get it working – MAMN84 Jan 05 '14 at 01:12
  • It only work if I set the foreground color to yellow and the background color to white. Weird!!!! – MAMN84 Jan 05 '14 at 01:45
  • 1
    @Rob VS, funny enough people usually thank the question answerer but all too often I am very grateful for the person who asked the question in the first place. Thanks for saving me from 30 mins of head scratching! – simplexity Aug 09 '17 at 18:52

1 Answers1

11

After 2 days on this problem

CATextLayer *text = [CATextLayer layer];
text.string = @"Your Text";
text.frame = CGRectMake(0, 0, 320, 50);
CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"HelveticaNeue-UltraLight");
text.font = font;
text.fontSize = 20;
text.foregroundColor = [UIColor whiteColor].CGColor;
[text display];
[aLayer addSublayer:text];
[aLayer display];

The secret is calling [CALayer display] method

MAMN84
  • 1,400
  • 2
  • 13
  • 22
  • Holy crap!! [CALayer display] and [CATextLayer display] did the trick. I had just converted my code to mimic Apple's AVSimpleEditoriOS sample code and it still didn't work (just about the only diff was the .mov file to which I was adding titles). btw, Apple's code does not call 'display'. Thank dude!! – Rob VS Jan 06 '14 at 03:59
  • 1
    I would recommend using displayIfNeeded instead of display, as display is not supposed to be called directly. – adriaan Jan 07 '14 at 05:46
  • Thank you. This magically solved it for me after too long banging my head on my desk. – crgt Mar 22 '17 at 21:10
  • Haha, 3 years later and this is still saving the day! Thanks @MAMN84 – simplexity Aug 09 '17 at 18:51
  • save my day and night :). Thanks – jpulikkottil Aug 24 '19 at 16:34
  • 2023... still the same issue. But this works! Thanks a lot! – Jory de Kort Apr 05 '23 at 11:41