2013-01-19 25 views
1

我有下一個問題(示例代碼如下):
我使用CATextLayerNSAttributedString來顯示風格化文本。所有的工作都很好,直到我爲屬性添加筆劃。當我添加筆畫時 - 文字變得不可見並且在顯示中我只能看到筆畫。 請,我不明白會發生什麼,爲什麼我不能同時使用文字和筆畫? 謝謝。加入筆畫後文字變得不可見

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]; 
+0

你的中風是什麼顏色? –

+0

前景色和筆觸顏色不同。 – Lexandr

+0

看看這個鏈接,看看你是否能找到任何東西https://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_text/dq_text.html –

回答

14

你strokeWidth必須爲負文字和中風和積極的僅填寫中風和中風。 From Apple Docs:

kCTStrokeWidthAttributeName。此屬性解釋爲字體磅值的百分比,用於控制文本繪圖模式:正值僅影響繪圖;負值是筆畫和填充。

0

使用kCGTextFillStroke - 這並在同一時間