0

I want to draw an NSAttributedString in a rect, just like I would do with a normal string: [normalString drawInRect:rect]; but I can't figure out how. I don't want any UILabel subclasses since I'm implementing a fast scrolling UITableView with no views, so it needs to be drawn. The documentation shows that drawing is only available on Mac.

Is drawing an NSAttributedString not possible on iOS?

3
  • Is CATextLayer not adequate? Commented Apr 30, 2012 at 0:30
  • Wouldn't this involve adding more views? I'd have to add the layer as a sublayer right? Commented Apr 30, 2012 at 0:35
  • @SedateAlien: CATextLayer is good, and may be suitable for this particular tast. However, it doesn't obey all the formatting that can be contained in NSAttributedString. See CATextLayer + NSAttributtedString + CTParagraphStyleRef. Commented Apr 30, 2012 at 10:34

1 Answer 1

2

You have to use Core Text to draw attributed strings on iOS.

The basic procedure would be to create a CTFramesetter from the string and a rectangular CGPath (or any other shape you may want), then create the frame using CTFramesetterCreateFrame and draw it with CTFrameDraw.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.