Lex*_*ndr 1 quartz-graphics core-text ios
我有下一个问题(下面的示例代码):
我正在使用CATextLayer并NSAttributedString显示风格化的文本.一切正常,直到我为属性添加笔划.当我添加笔划时 - 文本变得不可见并且在显示中我只能看到笔划.拜托,我无法理解会发生什么,为什么我不能同时使用文字和笔画?谢谢.
UIFont* font = [UIFont fontWithName: size:];
UIColor* strokeColor = [UIColor colorWithRed: green: blue: alpha:1.f];
UIColor* foregroundColor = [UIColor colorWithRed: green: blue: alpha:1.f];
CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithNameAndSize(...);
CTFontRef ctFont = CTFontCreateWithFontDescriptor(...);
NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
strokeWidth, kCTStrokeWidthAttributeName,
[strokeColor CGColor], kCTStrokeColorAttributeName,
ctFont, kCTFontAttributeName,
[foregroundColor CGColor], kCTForegroundColorAttributeName,
nil];
NSAttributedString* attributedText =
[[NSAttributedString alloc] initWithString:text attributes:attributes];
CATextLayer* infoTextLayer = [[[CATextLayer alloc] init] autorelease];
infoTextLayer.string = attributedText;
...
infoTextLayer.frame = frame;
[self.layer addSublayer:infoTextLayer];
Run Code Online (Sandbox Code Playgroud)
dim*_*xyu 14
您的strokeWidth对于文本和笔划必须为负,对于仅笔划必须为正.来自Apple Docs:
kCTStrokeWidthAttributeName.此属性(按字体点大小的百分比解释)控制文本绘制模式:正值仅影响绘图; 中值和填充的负值.