[update]最后,我发现问题在4s / 5和5s / 6之间。 在5s / 6模拟器和真实手机中没有任何第一行缩进。 iOS版本是8.2。
缩进设置在8.1.2(5c)iPhone和模拟器中运行良好,但在我的ip6和另外5s(均为8.1.3)中没有任何第一行缩进。
见截图:
任何人遇到同样的问题?
// indent
CTParagraphStyleSetting indentSetting;
indentSetting.spec = kCTParagraphStyleSpecifierFirstLineHeadIndent;
indentSetting.value = &indent;
indentSetting.valueSize = sizeof(float);
CTParagraphStyleSetting settings[] = {lineBreakMode,paragraphSpacing,LineSpacing,alignmentSetting,indentSetting};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(settings, 5); //第二个参数为settings的长度
textStyle = [NSDictionary dictionaryWithObjectsAndKeys:
(id)fontColor.CGColor, kCTForegroundColorAttributeName,
fontRef, kCTFontAttributeName,
kernRef,kCTKernAttributeName,
paragraphStyle,kCTParagraphStyleAttributeName,
nil]
attString=[[NSMutableAttributedString alloc] initWithString:text attributes:textStyle]; //1
CTFramesetterRef framesetter =
CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attString); //3
CTFrameRef frame =
CTFramesetterCreateFrame(framesetter,
CFRangeMake(0, [attString length]), path, NULL);
CTFrameDraw(frame, context); //4