伙计们。我已经用 Core Text 做了一些富文本编辑器工作。我想保持固定的行高,它真的可以用下面的代码来完成:
NSMutableAttributedString *_attributedText = [[NSMutableAttributedString alloc]initWithAttributedString:_attributedString] ;
CGFloat lineSpace=20;
CTParagraphStyleSetting lineSpaceStyle;
lineSpaceStyle.spec=kCTParagraphStyleSpecifierMaximumLineHeight;
lineSpaceStyle.valueSize=sizeof(lineSpace);
lineSpaceStyle.value=&lineSpace;
//CTLineBreakMode lineBreakMode = kCTLineBreakByCharWrapping;
CTParagraphStyleSetting settings[]={
lineSpaceStyle,
// {.spec = kCTParagraphStyleSpecifierLineBreakMode, .valueSize = sizeof(CTLineBreakMode), .value = (const void*)&lineBreakMode},
};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, sizeof(settings));
[_attributedText addAttribute:(id)kCTParagraphStyleAttributeName value:(id)paragraphStyle range:NSMakeRange(0, _attributedText.mutableString.length)];
_attributedString = [_attributedText copy];
[_attributedText release];
_attributedText = nil;
CFRelease(paragraphStyle);
然后我想在其中插入一个图像。我想用以下代码在图像上输入一些文本:
CTRunDelegateCallbacks callbacks = {
.version = kCTRunDelegateVersion1,
.dealloc = AttachmentRunDelegateDealloc,
.getAscent = AttachmentRunDelegateGetAscent,
.getDescent = AttachmentRunDelegateGetDescent,
.getWidth = AttachmentRunDelegateGetWidth
};
CTRunDelegateRef Rundelegate = CTRunDelegateCreate(&callbacks, [image retain]); //3
NSMutableDictionary *attrDictionaryDelegate = [NSMutableDictionary dictionaryWithDictionary:self.defaultAttributes];
[attrDictionaryDelegate setObject:image
forKey:EGOTextAttachmentAttributeName];
[attrDictionaryDelegate setObject:(id)Rundelegate
forKey:(NSString*)kCTRunDelegateAttributeName];
[attrDictionaryDelegate setObject:fulltext
forKey:EGOTextAttachmentOriginStringKey];
NSAttributedString *newString = [[NSAttributedString alloc] initWithString:EGOTextAttachmentPlaceholderString
attributes:attrDictionaryDelegate];
[attrString replaceCharactersInRange:[result resultByAdjustingRangesWithOffset:attrString.length-astring.length].range
withAttributedString:newString];
换句话说,有没有一些方法可以让 Core Text 的图像上的文本布局??????任何人????