Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is a paragraph defined in an NSAttributedString?

I see that there is an attribute name (NSParagraphStyleAttributeName) for applying paragraph styles to text in Cocoa. Text is stored in an NSAttributedString, but what defines a "paragraph" in that string -- is it the newline character \n? Other characters? If it's a \n, then how do you create a new line without starting a new paragraph. And lastly, when you attach a ParagraphStyle to the string, do you have to use the exact range of the whole paragraph, or can you put it on any sub-range in the paragraph. If it can be a sub-range, how does the system handle two or more ParagraphStyles on the same paragraph?

thanks, Rob

like image 884
Rob N Avatar asked Dec 09 '10 23:12

Rob N


People also ask

What is an NSAttributedString?

An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. An association of characters and their attributes is called an attributed string.

What is Nsmutableattributedstring?

A mutable string with associated attributes (such as visual style, hyperlinks, or accessibility data) for portions of its text.

What is attributed text Swift?

A value type for a string with associated attributes for portions of its text.


1 Answers

I got an answer from Douglas on Apple's cocoa-dev mailing list:

http://lists.apple.com/archives/Cocoa-dev/2010/Dec/msg00347.html

I'll copy what he wrote here:

Any of the standard paragraph separators can be used (\n, \r, \r\n, Unicode paragraph separator). Use the Unicode line separator character to start a new line without a paragraph break. It is best to apply a paragraph style to an entire paragraph; if that is not done, then the paragraph style attribute will be automatically fixed at attribute fixing time so that it is constant over each paragraph range, because that is needed at layout time.

like image 128
Rob N Avatar answered Sep 24 '22 13:09

Rob N