NSMutableAttributedString
NSMutableAttributedString 是可变的富文本字符串,可用于拼接、替换文本以及增删属性。
实例成员 (Instance members)
Section titled “实例成员 (Instance members)”replaceCharactersInRangeWithString
Section titled “replaceCharactersInRangeWithString”在范围内用字符串替换文本。
replaceCharactersInRangeWithString(range: any, str: string): voidParameters:
| Name | Type | Description |
|---|---|---|
range | any | 范围(如 { location, length })。 |
str | string | 替换字符串。 |
Return Value:
- 无。
replaceCharactersInRangeWithAttributedString
Section titled “replaceCharactersInRangeWithAttributedString”在范围内用富文本替换。
replaceCharactersInRangeWithAttributedString(range: any, attrString: NSAttributedString): voidParameters:
| Name | Type | Description |
|---|---|---|
range | any | 范围。 |
attrString | NSAttributedString | 替换富文本。 |
Return Value:
- 无。
insertAttributedStringAtIndex
Section titled “insertAttributedStringAtIndex”在指定位置插入富文本。
insertAttributedStringAtIndex(attrString: NSAttributedString, loc: number): voidParameters:
| Name | Type | Description |
|---|---|---|
attrString | NSAttributedString | 要插入的富文本。 |
loc | number | 插入位置索引。 |
Return Value:
- 无。
appendAttributedString
Section titled “appendAttributedString”在末尾追加富文本。
appendAttributedString(attrString: NSAttributedString): voidParameters:
| Name | Type | Description |
|---|---|---|
attrString | NSAttributedString | 要追加的富文本。 |
Return Value:
- 无。
deleteCharactersInRange
Section titled “deleteCharactersInRange”删除范围内字符。
deleteCharactersInRange(range: any): voidParameters:
| Name | Type | Description |
|---|---|---|
range | any | 要删除的范围。 |
Return Value:
- 无。
setAttributedString
Section titled “setAttributedString”用富文本整体替换内容。
setAttributedString(attrString: NSAttributedString): voidParameters:
| Name | Type | Description |
|---|---|---|
attrString | NSAttributedString | 新内容富文本。 |
Return Value:
- 无。
setAttributesRange
Section titled “setAttributesRange”在范围内设置属性字典。
setAttributesRange(attrs: NSDictionary, range: any): voidParameters:
| Name | Type | Description |
|---|---|---|
attrs | NSDictionary | 属性字典。 |
range | any | 范围。 |
Return Value:
- 无。
addAttributeValueRange
Section titled “addAttributeValueRange”在范围内添加单属性。
addAttributeValueRange(name: string, value: any, range: any): voidParameters:
| Name | Type | Description |
|---|---|---|
name | string | 属性名。 |
value | any | 属性值。 |
range | any | 范围。 |
Return Value:
- 无。
addAttributesRange
Section titled “addAttributesRange”在范围内添加多属性。
addAttributesRange(attrs: NSDictionary, range: any): voidParameters:
| Name | Type | Description |
|---|---|---|
attrs | NSDictionary | 属性字典。 |
range | any | 范围。 |
Return Value:
- 无。
removeAttributeRange
Section titled “removeAttributeRange”在范围内移除某属性。
removeAttributeRange(name: string, range: any): voidParameters:
| Name | Type | Description |
|---|---|---|
name | string | 属性名。 |
range | any | 范围。 |
Return Value:
- 无。
fixAttributesInRange
Section titled “fixAttributesInRange”在范围内修复/规范化属性(若在运行环境中可用)。
fixAttributesInRange(range: any): voidParameters:
| Name | Type | Description |
|---|---|---|
range | any | 范围。 |
Return Value:
- 无。
beginEditing
Section titled “beginEditing”开始编辑批处理。
beginEditing(): voidReturn Value:
- 无。
endEditing
Section titled “endEditing”结束编辑批处理。
endEditing(): voidReturn Value:
- 无。
mutableString
Section titled “mutableString”底层可变字符串(可直接修改文本)。
mutableString(): NSMutableStringReturn Value:
NSMutableString: 底层可变字符串。
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: 文件包装器。
readFromFileURLOptionsDocumentAttributesError
Section titled “readFromFileURLOptionsDocumentAttributesError”从文件 URL 读取(若在运行环境中可用)。
readFromFileURLOptionsDocumentAttributesError(url: NSURL, opts: NSDictionary, dict: any, error: any): booleanParameters:
| Name | Type | Description |
|---|---|---|
url | NSURL | 文件 URL。 |
opts | NSDictionary | 读取选项。 |
dict | any | 输出参数,接收文档属性。 |
error | any | 输出参数,接收错误。 |
Return Value:
boolean: 是否读取成功。
readFromDataOptionsDocumentAttributesError
Section titled “readFromDataOptionsDocumentAttributesError”从 NSData 读取(若在运行环境中可用)。
readFromDataOptionsDocumentAttributesError(data: NSData, opts: NSDictionary, dict: any, error: any): booleanParameters:
| Name | Type | Description |
|---|---|---|
data | NSData | 源数据。 |
opts | NSDictionary | 读取选项。 |
dict | any | 输出参数,接收文档属性。 |
error | any | 输出参数,接收错误。 |
Return Value:
boolean: 是否读取成功。
类成员 (Class members)
Section titled “类成员 (Class members)”当前运行时未额外暴露 NSMutableAttributedString 的类成员。