CTFrame:可见字符串范围 = (0, 0){type = mutable-small, count = 0, values = ()}
我发现这个问题只发生在 ios6 中,并且只绘制图像。最终,我发现这段代码可能是问题所在:
if (imagename) {
//render empty space for drawing the image in the text //1
CTRunDelegateCallbacks callbacks;
callbacks.version = kCTRunDelegateVersion1;
callbacks.getAscent = ascentCallback;
callbacks.getDescent = descentCallback;
callbacks.getWidth = widthCallback;
callbacks.dealloc = deallocCallback;
NSDictionary *imgAttr = @{@"width": [NSNumber numberWithFloat:self.customFaceSize.width],
@"height": [NSNumber numberWithFloat:self.customFaceSize.height],
@"descent" : [NSNumber numberWithFloat:0],
};
CFRetain((__bridge CFTypeRef)imgAttr);
CTRunDelegateRef delegate = CTRunDelegateCreate(&callbacks, (__bridge void *)(imgAttr));
NSDictionary *attrDictionaryDelegate = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)delegate,(NSString *)kCTRunDelegateAttributeName,
imagename,iCKeyFaceName,
[NSNumber numberWithLong:styleRange.location],iCkeyFaceLocation,
nil];
[*attributedString addAttributes:attrDictionaryDelegate range:styleRange];
[*attributedString addAttributes:[self attributesWithNude:nude] range:styleRange];
}else{
[*attributedString addAttributes:[self attributesWithNude:nude] range:styleRange];
}
我该怎么办?谢谢
最佳答案
我解决了这个问题,我发现 ios6 中的路径矩形有所不同。
CGRect drawingRect = self.bounds;
CGPathAddRect(path, NULL, drawingRect);
CTFrameRef textFrame = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,0), path, NULL);
drawingRect.size.height小于ios7及以上
so.i通过在ios6中为drawingRect.size.height添加小像素来修复它,并且它可以工作。 希望对你有帮助。
drawingRect.size.height += 2;
关于ios - 使用 coretext,在绘制图像和在 ios6 中,我得到 CTFrame 空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24602187/