我有一个带有图像附件的属性字符串,我需要向其中插入文本而不删除图像。我要做的第一件事是检测图像当前附加的索引。
下面是我正在使用的代码,但它并不总是有效,也许有更好的方法?
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/