Platforms to show: All Mac Windows Linux Cross-Platform
Back to NSAttributedStringMBS class.
NSAttributedStringMBS.boundingRectWithSize(size as NSSizeMBS, Options as Integer = 0) as NSRectMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 24.4 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
size: The width and height constraints to apply when computing the string’s bounding rectangle.
options: Additional drawing options to apply to the string during rendering. For a list of possible values, see NSStringDrawingOptions.
Returns a rectangle whose size component indicates the width and height required to draw the entire contents of the string.
You can use this method to compute the space required to draw the string. The constraints you specify in the size parameter are a guide for the renderer for how to size the string. However, the actual bounding rectangle returned by this method can be larger than the constraints if additional space is needed to render the entire string. Typically, the renderer preserves the width constraint and adjusts the height constraint as needed.
In iOS 7 and later, this method returns fractional sizes (in the size component of the returned rectangle); to use a returned size to size views, you must use raise its value to the nearest higher integer using the ceil function.
Special Considerations
To calculate the bounding rectangle, this method uses the baseline origin by default, so it behaves as a single line. To render the string in multiple lines, specify NSStringDrawingUsesLineFragmentOrigin in options. (see constants in NSGraphicsMBS class)
NSAttributedStringMBS.Constructor
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 19.0 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
NSAttributedStringMBS.Convert_Operator as string
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 18.4 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
NSAttributedStringMBS.copy as NSAttributedStringMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
NSAttributedStringMBS.CopyToClipboard as Boolean
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 18.0 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
NSAttributedStringMBS.dataFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil, byref error as NSErrorMBS) as memoryblock
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 16.0 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
offset and length: The range.
documentAttributes: A required dictionary specifying the document attributes. The dictionary contains values from Document Types and must at least contain NSDocumentTypeDocumentAttribute.
error: An in-out variable containing an encountered error, if any.
Returns the data for the attributed string, or nil if failure. When nil, error encapsulates the error information.
Raises an NSRangeException if any part of range lies beyond the end of the receiver’s characters.
NSAttributedStringMBS.docFormatFromRange(documentAttributes as dictionary = nil) as MemoryBlock
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 9.4 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Same as docFormatFromRange(0,length)
Returns nil on failure.
documentAttributes can optionally be a dictionary with document attributes like author or title.
See also:
Some examples using this method:
NSAttributedStringMBS.docFormatFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil) as MemoryBlock
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 7.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Returns nil on failure.
documentAttributes can optionally be a dictionary with document attributes like author or title.
See also:
NSAttributedStringMBS.fileWrapperFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil, byref Error as NSErrorMBS) as NSFileWrapperMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 16.0 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
offset and length: The range.
documentAttributes: A required dictionary specifying the document attributes. The dictionary contains values from Document Types and must at least contain NSDocumentTypeDocumentAttribute.
error: An in-out variable containing an encountered error, if any.
Returns a file wrapper for the appropriate document type, or nil if failure. When nil, error encapsulates the error information.
Raises an NSRangeException if any part of range lies beyond the end of the receiver’s characters.
NSAttributedStringMBS.GeneratePDF(PrintOptions as Variant = nil) as MemoryBlock
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 16.0 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
PrintOptions is optional NSPrintInfoMBS object for print settings like margin.
NSAttributedStringMBS.htmlString as string
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 7.8 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
Does not always work well, but can help.
(Apple has no official function for this)
Some examples using this method:
NSAttributedStringMBS.lineRangeForRange(range as NSRangeMBS) as NSRangeMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 18.1 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
Range: A range within the receiver. The value must not exceed the bounds of the receiver.
The range of characters representing the line or lines containing aRange, including the line termination characters.
NSAttributedStringMBS.mutableCopy as NSMutableAttributedStringMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 9.6 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
NSAttributedStringMBS.paragraphRangeForRange(range as NSRangeMBS) as NSRangeMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 18.1 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
Range: A range within the receiver. The range must not exceed the bounds of the receiver.
The range of characters representing the paragraph or paragraphs containing range, including the paragraph termination characters.
A paragraph is any segment of text delimited by a carriage return (U+000D), newline (U+000A), or paragraph separator (U+2029).
NSAttributedStringMBS.rangeOfTextBlock(textBlock as NSTextBlockMBS, location as Integer) as NSRangeMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 22.0 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
NSAttributedStringMBS.rangeOfTextList(list as NSTextListMBS, location as Integer) as NSRangeMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 18.1 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
list: The text list.
location: The location in the text list.
Returns the range of the given text list containing the location.
NSAttributedStringMBS.rangeOfTextTable(textTable as NSTextTableMBS, location as Integer) as NSRangeMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 22.0 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
NSAttributedStringMBS.rtf as MemoryBlock
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 9.4 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
Same as RTFFromRange(0,length)
NSAttributedStringMBS.RTFDFileWrapperFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil) as NSFileWrapperMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 16.0 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
offset and length: The range.
documentAttributes: A required dictionary specifying the document attributes. The dictionary contains values from Document Types and must at least contain NSDocumentTypeDocumentAttribute. If there are no document-level attributes, dict can be nil.
Returns a file wrapper containing the RTFD data.
The file wrapper also includes the document-level attributes in docAttributes, as explained in RTF Files and Attributed Strings.
Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.
You can save the file wrapper using the NSFileWrapper method writeToFile.
NSAttributedStringMBS.RTFDFromRange(documentAttributes as dictionary = nil) as MemoryBlock
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 9.4 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
Returns nil on failure.
Same as RTFDFromRange(0,length)
documentAttributes can optionally be a dictionary with document attributes like author or title.
See also:
NSAttributedStringMBS.RTFDFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil) as MemoryBlock
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 7.2 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
Returns nil on failure.
documentAttributes can optionally be a dictionary with document attributes like author or title.
See also:
NSAttributedStringMBS.RTFFromRange(documentAttributes as dictionary = nil) as MemoryBlock
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 7.2 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
Returns nil on failure.
Same as RTFFromRange(0,length)
documentAttributes can optionally be a dictionary with document attributes like author or title.
See also:
NSAttributedStringMBS.RTFFromRange(offset as Integer, length as Integer, documentAttributes as dictionary = nil) as MemoryBlock
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 7.2 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
Returns nil on failure.
documentAttributes can optionally be a dictionary with document attributes like author or title.
See also:
NSAttributedStringMBS.size as NSSizeMBS
| Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
| method | Cocoa Text | MBS MacBase Plugin | 24.4 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | All |
The minimum size required to draw the entire contents of the string.
Discussion
You can use this method prior to drawing to compute how much space is required to draw the string.
This method may return fractional sizes. When setting the size of your view, use the ceil function to round fractional values up to the nearest whole number.
The items on this page are in the following plugins: MBS MacBase Plugin.