Objective c 设置CTFrame中的行间距
我在一种二维码发生器中工作,它是一个Mac应用程序。 我知道如何绘制文本,但我不知道如何设置行距 我的代码:Objective c 设置CTFrame中的行间距,objective-c,macos,core-text,ctframe,Objective C,Macos,Core Text,Ctframe,我在一种二维码发生器中工作,它是一个Mac应用程序。 我知道如何绘制文本,但我不知道如何设置行距 我的代码: //准备字体 CTFontRef font=CTFontCreateWithName(CFSTR(“LucidaSansUnicode”),16,空; //创建路径 CGMutablePathRef gpath=CGPathCreateMutable(); cgpath-addrect(gpath,NULL,CGRectMake(10,0,pixelsWidth,pixelsHigh))
//准备字体
CTFontRef font=CTFontCreateWithName(CFSTR(“LucidaSansUnicode”),16,空;
//创建路径
CGMutablePathRef gpath=CGPathCreateMutable();
cgpath-addrect(gpath,NULL,CGRectMake(10,0,pixelsWidth,pixelsHigh));
CGContextSetTextDrawingMode(新上下文,kCGTextFill);
CGContextSetGrayFillColor(newcontext,0.0,1.0);
//创建属性化字符串
CFStringRef键[]={kCTFontAttributeName};
CFTypeRef值[]={font};
CFDictionaryRef attr=CFDictionaryCreate(NULL,(const void**)和key,(const void**)和value,
sizeof(键)/sizeof(键[0]),&kCFTypeDictionaryKeyCallBacks和&kCFTypeDictionaryValueCallBacks);
CFAttributedStringRef attrString=CFAttributedStringCreate(NULL,stringCode,attr);
CTFramesetterRef framesetter=CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrString);
CTFrameRef theFrame=CTFramesetterCreateFrame(framesetter,CFRangeMake(0,CFAttributedStringGetLength(attrString)),gpath,NULL);
//牵线
CTFrameDraw(theFrame,newcontext);
我一直在找,但什么也没找到。也许我必须使用CTLine
更新:
好的,我找到了这个,但它不能解决我的问题,我想要小于0.0点的行距。
尝试使用
kCTParagraphStyleSpecifierLineHeightMultiple
而不是kCTParagraphStyleSpecifierLineSpacingAdjustment
。这对我很管用。
请注意,1.0行距是1.2*yourLineHeight。尝试使用
KCTParraphStyleSpecifierLineheightMultiple
而不是KCTParraphStyleSpecifierLineSpacingAdjustment
。这对我很管用。
请注意,1.0行距等于1.2*yourLineHeight
CTTextAlignment paragraphAlignment = kCTLeftTextAlignment;
CGFloat maxLine = 0.0;
CTParagraphStyleSetting setting[2] = {
{kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), ¶graphAlignment},
{kCTParagraphStyleSpecifierLineSpacingAdjustment, sizeof(CGFloat), &maxLine}
};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(setting, 2);