O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Drawing Strings and Attributed Strings

Both NSString and NSAttributedString have methods that cause them to be drawn onto a view. NSAttributedString has the following methods:

f​u​n​c​ ​d​r​a​w​A​t​P​o​i​n​t​(​p​o​i​n​t​:​ ​N​S​P​o​i​n​t​)​

Draws the attributed string. point is the lower-left corner of the string.

f​u​n​c​ ​d​r​a​w​I​n​R​e​c​t​(​r​e​c​t​:​ ​N​S​R​e​c​t​)​

Draws the attributed string; all drawing occurs inside rect. If rect is too small for the string to fit, the drawing is clipped to fit inside rect.

v​a​r​ ​s​i​z​e​:​ ​N​S​S​i​z​e​ ​{​ ​g​e​t​ ​}​

Returns the size in points that the attributed string would be if drawn.

NSString has analogous methods. With NSString, you need to supply a dictionary ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required