cocoa - 检索 NSAttributedString 上的图像附件位置

标签 cocoa nsattributedstring

我有一个带有图像附件的属性字符串,我需要向其中插入文本而不删除图像。我要做的第一件事是检测图像当前附加的索引。

下面是我正在使用的代码,但它并不总是有效,也许有更好的方法?

 char charTemp;
    for(int i = 0; i < [mutableAttStr.string length]; i++){
        charTemp = [mutableAttStr.string characterAtIndex:i];

        if (!isalpha(charTemp) && !isspace(charTemp) && !iscntrl(charTemp) && !ispunct(charTemp)) {
       //     NSLog(@"isAttachment");
            [attachmentArrayCharIndex addObject:[NSNumber numberWithInt:i]];
        }
    }

最佳答案

首先,使用unichar,而不是char

其次,NSTextAttachment.h 声明 NSAttachmentCharacter,您可以使用它来确定附件在属性字符串中的位置。

关于cocoa - 检索 NSAttributedString 上的图像附件位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7097800/

相关文章:

iphone - 从 UIImage 获取数据

objective-c - 有没有办法查看撤消堆栈?

cocoa - NSTableView 行的索引

html - iOS 渲染带有超链接和图像的 HTML 标签

cocoa - 使用通知从 NSTask 实时获取数据不起作用

cocoa - 辅助功能:ScrollView 自动滚动到点击 "TAB"时不可见的 View

swift - 如何在 Swift 中将特定属性添加到 NSAttributedString

objective-c - 存储和检索NSAttributedString

ios - 将文本样式化到 UITextView

html - NSAttributedString 的 initWithHTML 的默认 DPI 是多少?