我有下一个问题(下面的示例代码):
我正在使用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];