Bearbeiten

Freigeben über


NSAttributedString Constructors

Definition

Overloads

NSAttributedString()

Default constructor that initializes a new instance of this class with no parameters.

NSAttributedString(NSData, NSDictionary, NSDictionary, NSError)
NSAttributedString(NSUrl, NSDictionary, NSDictionary, NSError)
NSAttributedString(NSUrl, NSAttributedStringDocumentAttributes, NSDictionary, NSError)
NSAttributedString(NSData, NSAttributedStringDocumentAttributes, NSDictionary, NSError)
NSAttributedString(NSUrl, NSAttributedStringDocumentAttributes, NSError)
NSAttributedString(NSData, NSUrl, NSDictionary)
NSAttributedString(NSData, NSDictionary, NSDictionary)
NSAttributedString(NSData, NSAttributedStringDocumentAttributes, NSError)
NSAttributedString(NSData, NSAttributedStringDocumentAttributes, NSDictionary)
NSAttributedString(String, UIStringAttributes)
NSAttributedString(String, NSDictionary)
NSAttributedString(String, UIFont, UIColor, UIColor, UIColor, NSParagraphStyle, NSLigatureType, Single, NSUnderlineStyle, NSShadow, Single, NSUnderlineStyle)

Creates a UIKit attributed string with the specified attributes in the parameters.

NSAttributedString(String, NSDictionary)

Creates an NSAttributedString with user defined attributes specified in a dictionary.

NSAttributedString(String, NSStringAttributes)
NSAttributedString(NSUrl, NSError)
NSAttributedString(NSUrl, NSDictionary)
NSAttributedString(NSFileWrapper, NSDictionary)
NSAttributedString(NSData, NSError)
NSAttributedString(NSData, NSDictionary)
NSAttributedString(String)
NSAttributedString(IntPtr)

A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

NSAttributedString(NSObjectFlag)

Constructor to call on derived classes to skip initialization and merely allocate the object.

NSAttributedString(NSCoder)

A constructor that initializes the object from the data stored in the unarchiver object.

NSAttributedString(NSAttributedString)
NSAttributedString(String, CTStringAttributes)

Creates an NSAttributedString for use with CoreText rendering functions.

NSAttributedString(String, NSFont, NSColor, NSColor, NSColor, NSColor, NSColor, NSUnderlineStyle, NSUnderlineStyle, NSParagraphStyle, Single, NSShadow, NSUrl, Boolean, NSTextAttachment, NSLigatureType, Single, Single, Single, Single, NSCursor, String, Int32, NSGlyphInfo, NSArray, Boolean, NSTextLayoutOrientation, NSTextAlternatives, NSSpellingState)

NSAttributedString()

Default constructor that initializes a new instance of this class with no parameters.

[Foundation.Export("init")]
public NSAttributedString ();
Attributes

Applies to

NSAttributedString(NSData, NSDictionary, NSDictionary, NSError)

[Foundation.Export("initWithData:options:documentAttributes:error:")]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 7, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public NSAttributedString (Foundation.NSData data, Foundation.NSDictionary options, out Foundation.NSDictionary resultDocumentAttributes, ref Foundation.NSError error);
[Foundation.Export("initWithData:options:documentAttributes:error:")]
public NSAttributedString (Foundation.NSData data, Foundation.NSDictionary options, out Foundation.NSDictionary docAttributes, out Foundation.NSError error);
new Foundation.NSAttributedString : Foundation.NSData * Foundation.NSDictionary *  *  -> Foundation.NSAttributedString
new Foundation.NSAttributedString : Foundation.NSData * Foundation.NSDictionary *  *  -> Foundation.NSAttributedString

Parameters

data
NSData
options
NSDictionary

To be added.

This parameter can be null.

resultDocumentAttributesdocAttributes
NSDictionary
error
NSError
Attributes

Applies to

NSAttributedString(NSUrl, NSDictionary, NSDictionary, NSError)

public NSAttributedString (Foundation.NSUrl url, Foundation.NSDictionary options, out Foundation.NSDictionary resultDocumentAttributes, out Foundation.NSError error);
[Foundation.Export("initWithURL:options:documentAttributes:error:")]
public NSAttributedString (Foundation.NSUrl url, Foundation.NSDictionary options, out Foundation.NSDictionary resultDocumentAttributes, out Foundation.NSError error);
new Foundation.NSAttributedString : Foundation.NSUrl * Foundation.NSDictionary *  *  -> Foundation.NSAttributedString

Parameters

url
NSUrl
options
NSDictionary

To be added.

This parameter can be null.

resultDocumentAttributes
NSDictionary
error
NSError
Attributes

Applies to

NSAttributedString(NSUrl, NSAttributedStringDocumentAttributes, NSDictionary, NSError)

[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 7, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public NSAttributedString (Foundation.NSUrl url, Foundation.NSAttributedStringDocumentAttributes options, out Foundation.NSDictionary resultDocumentAttributes, out Foundation.NSError error);
public NSAttributedString (Foundation.NSUrl url, Foundation.NSAttributedStringDocumentAttributes options, out Foundation.NSDictionary resultDocumentAttributes, out Foundation.NSError error);
new Foundation.NSAttributedString : Foundation.NSUrl * Foundation.NSAttributedStringDocumentAttributes *  *  -> Foundation.NSAttributedString

Parameters

url
NSUrl
resultDocumentAttributes
NSDictionary
error
NSError
Attributes

Applies to

NSAttributedString(NSData, NSAttributedStringDocumentAttributes, NSDictionary, NSError)

[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 7, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public NSAttributedString (Foundation.NSData data, Foundation.NSAttributedStringDocumentAttributes options, out Foundation.NSDictionary resultDocumentAttributes, out Foundation.NSError error);
public NSAttributedString (Foundation.NSData data, Foundation.NSAttributedStringDocumentAttributes options, out Foundation.NSDictionary resultDocumentAttributes, out Foundation.NSError error);
new Foundation.NSAttributedString : Foundation.NSData * Foundation.NSAttributedStringDocumentAttributes *  *  -> Foundation.NSAttributedString

Parameters

data
NSData
resultDocumentAttributes
NSDictionary
error
NSError
Attributes

Applies to

NSAttributedString(NSUrl, NSAttributedStringDocumentAttributes, NSError)

public NSAttributedString (Foundation.NSUrl url, Foundation.NSAttributedStringDocumentAttributes documentAttributes, ref Foundation.NSError error);
new Foundation.NSAttributedString : Foundation.NSUrl * Foundation.NSAttributedStringDocumentAttributes *  -> Foundation.NSAttributedString

Parameters

url
NSUrl
error
NSError

Applies to

NSAttributedString(NSData, NSUrl, NSDictionary)

[Foundation.Export("initWithHTML:baseURL:documentAttributes:")]
public NSAttributedString (Foundation.NSData htmlData, Foundation.NSUrl baseUrl, out Foundation.NSDictionary docAttributes);
new Foundation.NSAttributedString : Foundation.NSData * Foundation.NSUrl *  -> Foundation.NSAttributedString

Parameters

htmlData
NSData
baseUrl
NSUrl
docAttributes
NSDictionary
Attributes

Applies to

NSAttributedString(NSData, NSDictionary, NSDictionary)

[Foundation.Export("initWithHTML:options:documentAttributes:")]
public NSAttributedString (Foundation.NSData data, Foundation.NSDictionary options, out Foundation.NSDictionary resultDocumentAttributes);
new Foundation.NSAttributedString : Foundation.NSData * Foundation.NSDictionary *  -> Foundation.NSAttributedString

Parameters

data
NSData
options
NSDictionary
resultDocumentAttributes
NSDictionary
Attributes

Applies to

NSAttributedString(NSData, NSAttributedStringDocumentAttributes, NSError)

public NSAttributedString (Foundation.NSData data, Foundation.NSAttributedStringDocumentAttributes documentAttributes, ref Foundation.NSError error);
new Foundation.NSAttributedString : Foundation.NSData * Foundation.NSAttributedStringDocumentAttributes *  -> Foundation.NSAttributedString

Parameters

data
NSData
error
NSError

Applies to

NSAttributedString(NSData, NSAttributedStringDocumentAttributes, NSDictionary)

public NSAttributedString (Foundation.NSData data, Foundation.NSAttributedStringDocumentAttributes options, out Foundation.NSDictionary resultDocumentAttributes);
new Foundation.NSAttributedString : Foundation.NSData * Foundation.NSAttributedStringDocumentAttributes *  -> Foundation.NSAttributedString

Parameters

data
NSData
resultDocumentAttributes
NSDictionary

Applies to

NSAttributedString(String, UIStringAttributes)

public NSAttributedString (string str, UIKit.UIStringAttributes attributes);
new Foundation.NSAttributedString : string * UIKit.UIStringAttributes -> Foundation.NSAttributedString

Parameters

str
String
attributes
UIStringAttributes

Applies to

NSAttributedString(String, NSDictionary)

[Foundation.Export("initWithPath:documentAttributes:")]
public NSAttributedString (string path, out Foundation.NSDictionary resultDocumentAttributes);
new Foundation.NSAttributedString : string *  -> Foundation.NSAttributedString

Parameters

path
String
resultDocumentAttributes
NSDictionary
Attributes

Applies to

NSAttributedString(String, UIFont, UIColor, UIColor, UIColor, NSParagraphStyle, NSLigatureType, Single, NSUnderlineStyle, NSShadow, Single, NSUnderlineStyle)

Creates a UIKit attributed string with the specified attributes in the parameters.

public NSAttributedString (string str, UIKit.UIFont font = null, UIKit.UIColor foregroundColor = null, UIKit.UIColor backgroundColor = null, UIKit.UIColor strokeColor = null, UIKit.NSParagraphStyle paragraphStyle = null, Foundation.NSLigatureType ligatures = Foundation.NSLigatureType.Default, float kerning = 0, Foundation.NSUnderlineStyle underlineStyle = Foundation.NSUnderlineStyle.PatternSolid, UIKit.NSShadow shadow = null, float strokeWidth = 0, Foundation.NSUnderlineStyle strikethroughStyle = Foundation.NSUnderlineStyle.PatternSolid);
new Foundation.NSAttributedString : string * UIKit.UIFont * UIKit.UIColor * UIKit.UIColor * UIKit.UIColor * UIKit.NSParagraphStyle * Foundation.NSLigatureType * single * Foundation.NSUnderlineStyle * UIKit.NSShadow * single * Foundation.NSUnderlineStyle -> Foundation.NSAttributedString

Parameters

str
String

String to create.

font
UIFont

Desired font (or null, if none is desired).

foregroundColor
UIColor

Desired foreground color (or null if none is desired).

backgroundColor
UIColor

Desired background color (or null if none is desired)..

strokeColor
UIColor

Desired stroke color (or null if none is desired).

paragraphStyle
NSParagraphStyle
ligatures
NSLigatureType
kerning
Single
underlineStyle
NSUnderlineStyle
shadow
NSShadow

Desired shadow.

strokeWidth
Single

Desired stroked width..

strikethroughStyle
NSUnderlineStyle

Remarks

This is the recommended constructor for NSAttributedString objects that are intended to be unique.

The advantage of this constructor is that other than the string, every parameter is optional. It provides a convenient way of creating the objects

//
// This example shows how to create an NSAttributedString for
// use with UIKit without creating the attributes separately
//
var text = new NSAttributedString (
    "Hello, World",
    font: UIFont.FromName ("HoeflerText-Regular", 24.0f),
    foregroundColor: UIColor.Red,
    strokeWidth: 4
);

For cases where the same attributes will be reused across multiple attributed strings, it is best to create the attributes using the UIStringAttributes class as that will share the same dictionary across multiple uses while this constructor creates a dictionary on demand for the specified attributes in the constructor.

Applies to

NSAttributedString(String, NSDictionary)

Creates an NSAttributedString with user defined attributes specified in a dictionary.

[Foundation.Export("initWithString:attributes:")]
public NSAttributedString (string str, Foundation.NSDictionary attributes);
new Foundation.NSAttributedString : string * Foundation.NSDictionary -> Foundation.NSAttributedString

Parameters

str
String

Strings

attributes
NSDictionary

Dictionary containing the attributes (keys) and their values attached to the strings.

This parameter can be null.

Attributes

Remarks

//
// This example shows how to create an NSAttributedString for
// use with UIKit using NSDictionaries
//
var dict = new NSMutableDictionary () {
    { NSAttributedString.FontAttributeName, UIFont.FromName ("HoeflerText-Regular", 24.0f), },
    { NSAttributedString.ForegroundColorAttributeName, UIColor.Black }
};

var text = new NSAttributedString (
	"Hello, World", dict);

Applies to

NSAttributedString(String, NSStringAttributes)

public NSAttributedString (string str, AppKit.NSStringAttributes attributes);
new Foundation.NSAttributedString : string * AppKit.NSStringAttributes -> Foundation.NSAttributedString

Parameters

str
String
attributes
NSStringAttributes

Applies to

NSAttributedString(NSUrl, NSError)

public NSAttributedString (Foundation.NSUrl url, ref Foundation.NSError error);
new Foundation.NSAttributedString : Foundation.NSUrl *  -> Foundation.NSAttributedString

Parameters

url
NSUrl
error
NSError

Applies to

NSAttributedString(NSUrl, NSDictionary)

[Foundation.Export("initWithURL:documentAttributes:")]
public NSAttributedString (Foundation.NSUrl url, out Foundation.NSDictionary resultDocumentAttributes);
new Foundation.NSAttributedString : Foundation.NSUrl *  -> Foundation.NSAttributedString

Parameters

url
NSUrl
resultDocumentAttributes
NSDictionary
Attributes

Applies to

NSAttributedString(NSFileWrapper, NSDictionary)

[Foundation.Export("initWithRTFDFileWrapper:documentAttributes:")]
public NSAttributedString (Foundation.NSFileWrapper wrapper, out Foundation.NSDictionary resultDocumentAttributes);
new Foundation.NSAttributedString : Foundation.NSFileWrapper *  -> Foundation.NSAttributedString

Parameters

wrapper
NSFileWrapper
resultDocumentAttributes
NSDictionary
Attributes

Applies to

NSAttributedString(NSData, NSError)

public NSAttributedString (Foundation.NSData data, ref Foundation.NSError error);
new Foundation.NSAttributedString : Foundation.NSData *  -> Foundation.NSAttributedString

Parameters

data
NSData
error
NSError

Applies to

NSAttributedString(NSData, NSDictionary)

[Foundation.Export("initWithDocFormat:documentAttributes:")]
public NSAttributedString (Foundation.NSData wordDocFormat, out Foundation.NSDictionary docAttributes);
new Foundation.NSAttributedString : Foundation.NSData *  -> Foundation.NSAttributedString

Parameters

wordDocFormat
NSData
docAttributes
NSDictionary
Attributes

Applies to

NSAttributedString(String)

[Foundation.Export("initWithString:")]
public NSAttributedString (string str);
new Foundation.NSAttributedString : string -> Foundation.NSAttributedString

Parameters

str
String
Attributes

Applies to

NSAttributedString(IntPtr)

A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

protected internal NSAttributedString (IntPtr handle);
new Foundation.NSAttributedString : nativeint -> Foundation.NSAttributedString

Parameters

handle
IntPtr

nativeint

Pointer (handle) to the unmanaged object.

Remarks

This constructor is invoked by the runtime infrastructure (GetNSObject(IntPtr)) to create a new managed representation for a pointer to an unmanaged Objective-C object. Developers should not invoke this method directly, instead they should call the GetNSObject method as it will prevent two instances of a managed object to point to the same native object.

Applies to

NSAttributedString(NSObjectFlag)

Constructor to call on derived classes to skip initialization and merely allocate the object.

protected NSAttributedString (Foundation.NSObjectFlag t);
new Foundation.NSAttributedString : Foundation.NSObjectFlag -> Foundation.NSAttributedString

Parameters

t
NSObjectFlag

Unused sentinel value, pass NSObjectFlag.Empty.

Remarks

This constructor should be called by derived classes when they completely construct the object in managed code and merely want the runtime to allocate and initialize the NSObject. This is required to implement the two-step initialization process that Objective-C uses, the first step is to perform the object allocation, the second step is to initialize the object. When developers invoke the constructor that takes the NSObjectFlag.Empty they take advantage of a direct path that goes all the way up to NSObject to merely allocate the object's memory and bind the Objective-C and C# objects together. The actual initialization of the object is up to the developer.

This constructor is typically used by the binding generator to allocate the object, but prevent the actual initialization to take place. Once the allocation has taken place, the constructor has to initialize the object. With constructors generated by the binding generator this means that it manually invokes one of the "init" methods to initialize the object.

It is the developer's responsibility to completely initialize the object if they chain up using the NSObjectFlag.Empty path.

In general, if the developer's constructor invokes the NSObjectFlag.Empty base implementation, then it should be calling an Objective-C init method. If this is not the case, developers should instead chain to the proper constructor in their class.

The argument value is ignored and merely ensures that the only code that is executed is the construction phase is the basic NSObject allocation and runtime type registration. Typically the chaining would look like this:

//
// The NSObjectFlag merely allocates the object and registers the
// C# class with the Objective-C runtime if necessary, but no actual
// initXxx method is invoked, that is done later in the constructor
//
// This is taken from Xamarin.iOS's source code:
//
[Export ("initWithFrame:")]
public UIView (System.Drawing.RectangleF frame) : base (NSObjectFlag.Empty)
{
// Invoke the init method now.
	var initWithFrame = new Selector ("initWithFrame:").Handle;
	if (IsDirectBinding)
		Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSend_CGRect (this.Handle, initWithFrame, frame);
	else
		Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_CGRect (this.SuperHandle, initWithFrame, frame);
}

Applies to

NSAttributedString(NSCoder)

A constructor that initializes the object from the data stored in the unarchiver object.

[Foundation.Export("initWithCoder:")]
[ObjCRuntime.DesignatedInitializer]
public NSAttributedString (Foundation.NSCoder coder);
new Foundation.NSAttributedString : Foundation.NSCoder -> Foundation.NSAttributedString

Parameters

coder
NSCoder

The unarchiver object.

Attributes

Remarks

This constructor is provided to allow the class to be initialized from an unarchiver (for example, during NIB deserialization). This is part of the NSCoding protocol.

If developers want to create a subclass of this object and continue to support deserialization from an archive, they should implement a constructor with an identical signature: taking a single parameter of type NSCoder and decorate it with the [Export("initWithCoder:"] attribute declaration.

The state of this object can also be serialized by using the companion method, EncodeTo.

Applies to

NSAttributedString(NSAttributedString)

[Foundation.Export("initWithAttributedString:")]
public NSAttributedString (Foundation.NSAttributedString other);
new Foundation.NSAttributedString : Foundation.NSAttributedString -> Foundation.NSAttributedString

Parameters

Attributes

Applies to

NSAttributedString(String, CTStringAttributes)

Creates an NSAttributedString for use with CoreText rendering functions.

public NSAttributedString (string str, CoreText.CTStringAttributes attributes);
new Foundation.NSAttributedString : string * CoreText.CTStringAttributes -> Foundation.NSAttributedString

Parameters

str
String

String.

attributes
CTStringAttributes

CoreText string attributes.

Applies to

NSAttributedString(String, NSFont, NSColor, NSColor, NSColor, NSColor, NSColor, NSUnderlineStyle, NSUnderlineStyle, NSParagraphStyle, Single, NSShadow, NSUrl, Boolean, NSTextAttachment, NSLigatureType, Single, Single, Single, Single, NSCursor, String, Int32, NSGlyphInfo, NSArray, Boolean, NSTextLayoutOrientation, NSTextAlternatives, NSSpellingState)

public NSAttributedString (string str, AppKit.NSFont font = null, AppKit.NSColor foregroundColor = null, AppKit.NSColor backgroundColor = null, AppKit.NSColor strokeColor = null, AppKit.NSColor underlineColor = null, AppKit.NSColor strikethroughColor = null, AppKit.NSUnderlineStyle underlineStyle = AppKit.NSUnderlineStyle.PatternSolid, AppKit.NSUnderlineStyle strikethroughStyle = AppKit.NSUnderlineStyle.PatternSolid, AppKit.NSParagraphStyle paragraphStyle = null, float strokeWidth = 0, AppKit.NSShadow shadow = null, Foundation.NSUrl link = null, bool superscript = false, AppKit.NSTextAttachment attachment = null, Foundation.NSLigatureType ligature = Foundation.NSLigatureType.Default, float baselineOffset = 0, float kerningAdjustment = 0, float obliqueness = 0, float expansion = 0, AppKit.NSCursor cursor = null, string toolTip = null, int characterShape = 0, AppKit.NSGlyphInfo glyphInfo = null, Foundation.NSArray writingDirection = null, bool markedClauseSegment = false, AppKit.NSTextLayoutOrientation verticalGlyphForm = AppKit.NSTextLayoutOrientation.Horizontal, AppKit.NSTextAlternatives textAlternatives = null, AppKit.NSSpellingState spellingState = AppKit.NSSpellingState.None);
new Foundation.NSAttributedString : string * AppKit.NSFont * AppKit.NSColor * AppKit.NSColor * AppKit.NSColor * AppKit.NSColor * AppKit.NSColor * AppKit.NSUnderlineStyle * AppKit.NSUnderlineStyle * AppKit.NSParagraphStyle * single * AppKit.NSShadow * Foundation.NSUrl * bool * AppKit.NSTextAttachment * Foundation.NSLigatureType * single * single * single * single * AppKit.NSCursor * string * int * AppKit.NSGlyphInfo * Foundation.NSArray * bool * AppKit.NSTextLayoutOrientation * AppKit.NSTextAlternatives * AppKit.NSSpellingState -> Foundation.NSAttributedString

Parameters

str
String
font
NSFont
foregroundColor
NSColor
backgroundColor
NSColor
strokeColor
NSColor
underlineColor
NSColor
strikethroughColor
NSColor
underlineStyle
NSUnderlineStyle
strikethroughStyle
NSUnderlineStyle
paragraphStyle
NSParagraphStyle
strokeWidth
Single
shadow
NSShadow
link
NSUrl
superscript
Boolean
attachment
NSTextAttachment
ligature
NSLigatureType
baselineOffset
Single
kerningAdjustment
Single
obliqueness
Single
expansion
Single
cursor
NSCursor
toolTip
String
characterShape
Int32
glyphInfo
NSGlyphInfo
writingDirection
NSArray
markedClauseSegment
Boolean
verticalGlyphForm
NSTextLayoutOrientation
textAlternatives
NSTextAlternatives
spellingState
NSSpellingState

Applies to