Another quickie
If you use -[NSAttributedString drawAtPoint:]
, you may be surprised to find that it doesn't respect NSParagraphStyle
s in the receiver's attributes. The documentation hints at why:
The width (height for vertical layout) of the rendering area is unlimited, unlike
drawInRect:
, which uses a bounding rectangle. As a result, this method renders the text in a single line.
Well, it will actually respect any newlines when measuring and drawing the text. You won't just get a single line. What it really means is that you don't get paragraph styles applied.
Solution: Use -[NSAttributedString drawInRect:]
instead.
I imagine that the same rule applies to -[NSString drawAtPoint:withAttributes:]
and -[NSString drawInRect:withAttributes:]
as well, since the former method has the same note in its documentation (and is probably implemented using -[NSAttributedString drawAtPoint:]
).
0 comments:
Post a Comment
<< Home