2013-01-19 3 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은 뇌졸중의 텍스트와 뇌졸중에 대한 부정적이고 긍정적이어야 동시에 작성 스트로크 않습니다. Apple 문서에서 :

kCTStrokeWidthAttributeName. 이 속성은 글꼴 크기의 백분율로 해석되어 텍스트 그리기 모드를 제어합니다. 음수 값은 획 및 채우기입니다.

0

사용 kCGTextFillStroke -

관련 문제