Search code examples
iosobjective-cword-wrap

Objective-C (IOS 6.1+): Draw Text in a shape or path


I was wondering if there is an "easy" way to draw text in a shape or a view or a path so that the characters wrap if the text line is too long (even with fonts with different sizes).

Below just an picture to describe the idea...

How can i check that a particular character size goes beyond the shape border and therefore the characters should be wrapped?

Any help on this...highly appreciated... :-) Thank you in advance.

enter image description here


Solution

  • There's no direct way to do this on iOS. (At least Apple doesn't provide a way).

    You will have to do it yourself - create a CGPathRef of your shape. Then use CGPathGetPathBoundingBox and CGPathContainsPoint to determine where to wrap your text. You can find out the size required for a string using -[NSString sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:].