
You create an NSAttributedString object in a number of different ways:
You can create a new string with the initWithString:, initWithString:attributes:initWithAttributedString: method. These methods initialize an attributed string with data you provIDe,as illustrated in the following example:
NSFont *Font = [NSFont FontWithname:@"Palatino-Roman" size:14.0]; |
For a List of attributes provIDed by the Application Kit framework see the Constants section in NSAttributedString Application Kit Additions Reference.
The attribute values assigned to an attributed string become the property of that string,and should not be modifIEd “behind the attributed string” by other objects. Doing so can render inconsistent the attributed string’s internal state. Always use NSMutableAttributedString’ssetAttributes:range: and related methods to change attribute values. See “Changing an Attributed String” for more details.
You can create an attributed string from rich text (RTF) or rich text with attachments (RTFD) data using the initialization methods,initWithRTF:documentAttributes:,102)">initWithRTFD:documentAttributes:initWithRTFDFileWrapper:documentAttributes:NSData *rtfData = ...; // assume rtfData is an NSData object containing valid RTF data
You can create an attributed string from HTML data using the initialization methods initWithHTML:documentAttributes: andinitWithHTML:baseURL:documentAttributes:. The methods return text attributes defined by the HTML as the attributes of the string. They return document-level attributes defined by the HTML,such as paper and margin sizes,by reference to an NSDictionary object,as described in “RTF Files and Attributed Strings.” The methods translate HTML as well as possible into structures of the Cocoa text system,but the Application Kit does not provIDe complete,true rendering of arbitrary HTML.
Multicore consIDerations: Since Mac OS X v10.4,102)">NSAttributedString has used WebKit for all import (but not for export) of HTML documents. Because WebKit document loading is not thread safe,this has not been safe to use on background threads. For applications linked on Mac OS X v10.5 and later,if NSAttributedString imports HTML documents on any but the main thread,the use of WebKit is transferred to the main thread viaperformSelectorOnMainThread:withObject:waitUntilDone:. This makes the operation thread safe,but it requires that the main thread be executing the run loop in one of the common modes. This behavior can be overrIDden by setting the value of the standard user defaultNSRunWebKitOnAppKitThread to either YES (to obtain the new behavior regardless of linkage) or NO (to obtain the old behavior regardless of linkage).
以上是内存溢出为你收集整理的Creating Attributed Strings in Cocoa全部内容,希望文章能够帮你解决Creating Attributed Strings in Cocoa所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)