NSAttributedString
NSAttributedString 表示带属性(字体、颜色、段落样式等)的只读富文本。你可能会在 UI 文本渲染、富文本评论/编辑等场景中遇到它。
实例成员 (Instance members)
Section titled “实例成员 (Instance members)”string
Section titled “string”纯文本内容。
string(): stringReturn Value:
string: 纯文本字符串。
length
Section titled “length”字符长度。
length(): numberReturn Value:
number: 长度。
attributesAtIndexEffectiveRange
Section titled “attributesAtIndexEffectiveRange”指定位置的属性字典与有效范围。
attributesAtIndexEffectiveRange(location: number, range: any): NSDictionaryParameters:
| Name | Type | Description |
|---|---|---|
location | number | 索引。 |
range | any | 输出参数,接收有效范围。 |
Return Value:
NSDictionary: 该位置的属性字典。
attributeAtIndexEffectiveRange
Section titled “attributeAtIndexEffectiveRange”指定位置的某属性值与有效范围。
attributeAtIndexEffectiveRange(attrName: string, location: number, range: any): anyParameters:
| Name | Type | Description |
|---|---|---|
attrName | string | 属性名。 |
location | number | 索引。 |
range | any | 输出参数,接收有效范围。 |
Return Value:
any: 该位置的该属性值。
attributesAtIndexLongestEffectiveRangeInRange
Section titled “attributesAtIndexLongestEffectiveRangeInRange”指定位置的属性与最长有效范围(在限定范围内)。
attributesAtIndexLongestEffectiveRangeInRange(location: number, range: any, rangeLimit: any): NSDictionaryParameters:
| Name | Type | Description |
|---|---|---|
location | number | 索引。 |
range | any | 输出参数,接收有效范围。 |
rangeLimit | any | 限定范围。 |
Return Value:
NSDictionary: 属性字典。
attributeAtIndexLongestEffectiveRangeInRange
Section titled “attributeAtIndexLongestEffectiveRangeInRange”指定位置的某属性与最长有效范围(在限定范围内)。
attributeAtIndexLongestEffectiveRangeInRange(attrName: string, location: number, range: any, rangeLimit: any): anyParameters:
| Name | Type | Description |
|---|---|---|
attrName | string | 属性名。 |
location | number | 索引。 |
range | any | 输出参数,接收有效范围。 |
rangeLimit | any | 限定范围。 |
Return Value:
any: 属性值。
attributedSubstringFromRange
Section titled “attributedSubstringFromRange”取子富文本。
attributedSubstringFromRange(range: any): NSAttributedStringParameters:
| Name | Type | Description |
|---|---|---|
range | any | 范围(如 { location, length })。 |
Return Value:
NSAttributedString: 子富文本。
isEqualToAttributedString
Section titled “isEqualToAttributedString”是否与另一富文本相等。
isEqualToAttributedString(other: NSAttributedString): booleanParameters:
| Name | Type | Description |
|---|---|---|
other | NSAttributedString | 另一富文本。 |
Return Value:
boolean: 是否相等。
enumerateAttributesInRangeOptionsUsingBlock
Section titled “enumerateAttributesInRangeOptionsUsingBlock”在范围内枚举属性。
enumerateAttributesInRangeOptionsUsingBlock(enumerationRange: any, opts: number, block: (attrs: NSDictionary, range: any, stop: any) => void): voidParameters:
| Name | Type | Description |
|---|---|---|
enumerationRange | any | 枚举范围。 |
opts | number | 枚举选项。 |
block | (attrs, range, stop) => void | 每段调用的回调。 |
Return Value:
- 无。
enumerateAttributeInRangeOptionsUsingBlock
Section titled “enumerateAttributeInRangeOptionsUsingBlock”在范围内枚举某属性。
enumerateAttributeInRangeOptionsUsingBlock(attrName: string, enumerationRange: any, opts: number, block: (value: any, range: any, stop: any) => void): voidParameters:
| Name | Type | Description |
|---|---|---|
attrName | string | 属性名。 |
enumerationRange | any | 枚举范围。 |
opts | number | 枚举选项。 |
block | (value, range, stop) => void | 每段调用的回调。 |
Return Value:
- 无。
绘制尺寸(若在运行环境中可用)。
size(): anyReturn Value:
any: 尺寸(如 { width, height })。
drawAtPoint
Section titled “drawAtPoint”在点绘制(若在运行环境中可用)。
drawAtPoint(point: any): voidParameters:
| Name | Type | Description |
|---|---|---|
point | any | 绘制点(如 { x, y })。 |
Return Value:
- 无。
drawInRect
Section titled “drawInRect”在矩形内绘制(若在运行环境中可用)。
drawInRect(rect: any): voidParameters:
| Name | Type | Description |
|---|---|---|
rect | any | 绘制矩形。 |
Return Value:
- 无。
drawWithRectOptionsContext
Section titled “drawWithRectOptionsContext”在矩形内按选项与上下文绘制(若在运行环境中可用)。
drawWithRectOptionsContext(rect: any, options: number, context: any): voidParameters:
| Name | Type | Description |
|---|---|---|
rect | any | 绘制矩形。 |
options | number | 绘制选项。 |
context | any | 图形上下文。 |
Return Value:
- 无。
boundingRectWithSizeOptionsContext
Section titled “boundingRectWithSizeOptionsContext”在给定尺寸与选项下计算边界矩形(若在运行环境中可用)。
boundingRectWithSizeOptionsContext(size: any, options: number, context: any): anyParameters:
| Name | Type | Description |
|---|---|---|
size | any | 约束尺寸。 |
options | number | 计算选项。 |
context | any | 图形上下文。 |
Return Value:
any: 边界矩形。
drawWithRectOptionsAttributesContext
Section titled “drawWithRectOptionsAttributesContext”在矩形内按选项、属性与上下文绘制(若在运行环境中可用)。
drawWithRectOptionsAttributesContext(rect: any, options: number, attributes: NSDictionary, context: any): voidParameters:
| Name | Type | Description |
|---|---|---|
rect | any | 绘制矩形。 |
options | number | 绘制选项。 |
attributes | NSDictionary | 默认属性。 |
context | any | 图形上下文。 |
Return Value:
- 无。
boundingRectWithSizeOptionsAttributesContext
Section titled “boundingRectWithSizeOptionsAttributesContext”在给定尺寸、选项与属性下计算边界矩形(若在运行环境中可用)。
boundingRectWithSizeOptionsAttributesContext(size: any, options: number, attributes: NSDictionary, context: any): anyParameters:
| Name | Type | Description |
|---|---|---|
size | any | 约束尺寸。 |
options | number | 计算选项。 |
attributes | NSDictionary | 默认属性。 |
context | any | 图形上下文。 |
Return Value:
any: 边界矩形。
dataFromRangeDocumentAttributesError
Section titled “dataFromRangeDocumentAttributesError”导出为数据(若在运行环境中可用)。
dataFromRangeDocumentAttributesError(range: any, dict: NSDictionary, error: any): NSDataParameters:
| Name | Type | Description |
|---|---|---|
range | any | 范围。 |
dict | NSDictionary | 文档属性。 |
error | any | 输出参数,接收错误。 |
Return Value:
NSData: 导出数据。
fileWrapperFromRangeDocumentAttributesError
Section titled “fileWrapperFromRangeDocumentAttributesError”导出为文件包装器(若在运行环境中可用)。
fileWrapperFromRangeDocumentAttributesError(range: any, dict: NSDictionary, error: any): anyParameters:
| Name | Type | Description |
|---|---|---|
range | any | 范围。 |
dict | NSDictionary | 文档属性。 |
error | any | 输出参数,接收错误。 |
Return Value:
any: 文件包装器。
类成员 (Class members)
Section titled “类成员 (Class members)”attributedStringWithAttachment
Section titled “attributedStringWithAttachment”从附件创建富文本(部分环境可用)。
static attributedStringWithAttachment(attachment: any): NSAttributedStringParameters:
| Name | Type | Description |
|---|---|---|
attachment | any | 附件对象。 |
Return Value:
NSAttributedString: 新富文本实例。