UIBezierPath and NSString


Hi all,

On page 106, the book states that drawRect: uses NSString to draw text. Could someone supply a code example of that? Or point me to the method which does this? I looked through the UIBezierPath docs and nothing jumped out of me.

I was thinking it might be interesting to try to create text with a gradient also.



I did a quick search for “draw” in the NSString Class Reference and found this: “Additionally, methods to support string drawing are described in NSString Additions, found in the Application Kit.” So I searched the Documentation (command-shift-0) for “NSString Additions” and found what you’re looking for. There you’ll find sections for tasks like computing metrics for single or multiple lines of text, drawing strings on a single line, in a given area, etc. There are several drawInRect: methods just like how we used drawInRect: on the UIImage to draw that in our custom view.

Here’s a link to the documentation: https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSString_UIKit_Additions/index.html

Note: Now that I looked at the online docs, it’s easier to see that several of the methods are deprecated since iOS 7.0, but you’ll still find what you need.

Good luck.