What to replace CATextLayer with porting from Mac to iPhone?

Discussion in 'iOS Programming' started by rossipoo, Jun 11, 2009.

  1. rossipoo macrumors regular

    Joined:
    Jun 7, 2009
    #1
    I have an application that makes extensive use of the CATextLayer class. The iPhone does not seem to have the class available however, which seems at least somewhat ridiculous.

    Is the solution to implement my own? That seems like quite a bit of work, I do need it to work with attributed strings.
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    There are no attributed strings either.

    I don't have any good advice for you other than ask this question at the Apple iPhone forum where some of the apple people might have a suggestion.
     
  3. rossipoo thread starter macrumors regular

    Joined:
    Jun 7, 2009
    #3
    How can so many iPhone apps exist with no proper string support. I could live without the attributed string, but I need something I can insert into a CALayer tree, and I need to be able to pick a font and size.

    Is subclassing CALayer and writing this myself really the only thing I can do?
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Apple considers that UIWebView and html is the way to display styled text. It does work in many cases.

    If you only need to draw a single line of text then that's easy enough using the UIStringDrawing methods. If you need wrapped multiline text then you'll have to use those methods to do the text layout and it won't be simple. I haven't yet needed to do this.

    UILabel and UITextView work well for display of single style text, but they work at the view level. I haven't done much at the layer level so I can't give you good advice on that.

    Another thought. There might be a way that you can get a screenshot of a UILabel saved into a CGImage and then add that to a CALayer instead of the actual text. If you only need a single line of text then it's not hard at all to draw text into an image. I think to get the "screenshot" you can use [label.layer renderInContext:]
     

Share This Page