MonoMac 0.0.0.0 MonoMac.Foundation.NSObject MonoMac.Foundation.Register("NSAttributedString", true) Strings that can be annotated with a set of attributes.

The NSAttributedString type represents a string that has a series of attributes applied uniformly.

The companion type can be used to create attributed strings that have overlapping attributes and whose contents can be modified after creation.

These types typically are used to attach information to elements of the string that dictate the font and colors to use as well as rendering attributes like kerning or how to render ligatures on a specific run of code.

These classes do not dictate the meaning or behavior of the attributes on a string, they merely keep track of the attributes. The actual meaning of these attributes is interpreted by the consumer of these objects.

NSAttributedStrings are created with a string and a set of attributes. The default constructor takes a string and an NSDictionary object where the keys represent the attributes and the values on each element represent the value of that attribute.

To simplify many common scenarios, MonoMac provides constructors with strong-types to easily create attributed strings for use with CoreText or UIKit. These constructors provide type-safety and eliminate programming errors caused by accidentally creating attributes that are not recognized by a backend.

To create NSAttributedStrings that you can use with CoreText's rendering, you create an instance of the class, set its properties to the attributes that you desire, and then invoke the NSAttributedString constructor with it.

To create NSAttributedStrings that you can use with UIKit's rendering, you create an instance of the class, set its properties to the attributes that you desire, and then invoke the NSAttributedString constructor with it.

The examples below show how to use the C# object initializer syntax to initialize the CTStringAttributes and the UIStringAttributes to setup your attributes. You can later use these attributes multiple times with different attributed strings:

`// // Using NSAttributedString with CoreText // var attributedString = new NSAttributedString ("Hello, world", new CTStringAttributes () { ForegroundColorFromContext = true, Font = new CTFont ("Arial", 24) }); // Pass the NSAttributedString to a CTLine and draw the CTLine. using (var textLine = new CTLine (attributedString)) { textLine.Draw (gctx); } // // Using NSAttributedString with UIKit // var myText = new NSAttributedString ("Hello, world", new UIStringAttributes () { ForegroundColor = UIColor.Red, KerningAdjustment = 3 }); label.AttributedText = myText;`

While both and are useful to create attributes that can later be used with attributed strings, it is also possible to use the constructor with C# named parameters for quickly creating attributed strings inline.

`// // 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 );`

It is also possible to create NSAttributedStrings with the NSDictionary API, although that does not offer any type safety nor prevents common errors. To use it, you typically use the various NSString properties that end in "AttributedName" that are part of this class.

`// // 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);` SimpleTextInput
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("init")
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Default constructor that initializes a new instance of this class with no parameters.
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("initWithAttributedString:")
  To be added.
  To be added.
  To be added.
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("initWithCoder:")
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  The unarchiver object.
  A constructor that initializes the object from the data stored in the unarchiver object.
  This constructor is provided to allow the class to be initialized from an unarchiver (for example, during NIB deserialization).
- Constructor
  0.0.0.0
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Unused sentinel value, pass NSObjectFlag.Empty.
  Constructor to call on derived classes when the derived class has an [Export] constructor.

  This constructor should be called by derived classes when they are initialized using an [Export] attribute. The argument value is ignore, typically the chaining would look like this:

  public class MyClass : BaseClass { [Export ("initWithFoo:")] public MyClass (string foo) : base (NSObjectFlag.Empty) { ... }
- Constructor
  0.0.0.0
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Pointer (handle) to the unmanaged object.
  A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

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

- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("initWithString:")
  To be added.
  To be added.
  To be added.
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("initWithDocFormat:documentAttributes:")
  To be added.
  To be added.
  To be added.
  To be added.
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("initWithString:attributes:")
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Strings
  Dictionary containing the attributes (keys) and their values attached to the strings.
  Creates an NSAttributedString with user defined attributes specified in a dictionary.
  // // 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);
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("initWithHTML:baseURL:documentAttributes:")
  To be added.
  To be added.
  To be added.
  To be added.
  To be added.
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("initWithData:options:documentAttributes:error:")
  To be added.
  To be added.
  To be added.
  To be added.
  To be added.
  To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  System.IntPtr The handle for this class. The pointer to the Objective-C class. Each MonoMac class mirrors an unmanaged Objective-C class. This value contains the pointer to the Objective-C class, it is similar to calling objc_getClass with the object name.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("drawAtPoint:")
  System.Void `` To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("drawInRect:")
  System.Void `` To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("drawWithRect:options:")
  System.Void `` `` To be added. To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("enumerateAttribute:inRange:options:usingBlock:")
  System.Void `` `` `` `` To be added. To be added. To be added. To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("enumerateAttributesInRange:options:usingBlock:")
  System.Void `` `` `` To be added. To be added. To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("attribute:atIndex:effectiveRange:")
  MonoMac.Foundation.NSObject `` `` `` To be added. To be added. To be added. To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("attribute:atIndex:longestEffectiveRange:inRange:")
  MonoMac.Foundation.NSObject `` `` `` `` To be added. To be added. To be added. To be added. To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("attributesAtIndex:effectiveRange:")
  MonoMac.Foundation.NSDictionary `` `` To be added. To be added. To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("attributesAtIndex:longestEffectiveRange:inRange:")
  MonoMac.Foundation.NSDictionary `` `` `` To be added. To be added. To be added. To be added. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("isEqualToAttributedString:")
  System.Boolean `` To be added. To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  get: MonoMac.Foundation.Export("length")
  System.Int32 To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  get: MonoMac.Foundation.Export("size")
  System.Drawing.SizeF To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  get: MonoMac.Foundation.Export("string")
  System.String To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString To be added. To be added. To be added.