我有下一個問題(示例代碼如下):
我使用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];
你的中風是什麼顏色? –
前景色和筆觸顏色不同。 – Lexandr
看看這個鏈接,看看你是否能找到任何東西https://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_text/dq_text.html –