다음 호 (아래 샘플 코드)가 있습니다.
양식화 된 텍스트를 표시하려면 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 –