는 the documentation에 따르면, CATextLayer 내부 글꼴 다듬기를 가능하게 할 수 있습니다 :CATextLayer에서 텍스트를 부드럽게하는 방법은 무엇입니까?
@implementation CATextLayerWithFontSmoothing
-(id)init {
self=[super init];
if (self) {
CALayer * whiteBackground = [CALayer layer];
CATextLayer * blackText = [CATextLayer layer];
[whiteBackground setBounds:NSMakeRect(0, 0, 300, 300)];
[blackText setBounds:NSMakeRect(0, 0, 300, 300)];
[whiteBackground setBackgroundColor:[NSColor whiteColor].CGColor];
[blackText setForegroundColor:[NSColor blackColor].CGColor];
[blackText setString:@"CATextLayer"];
[blackText setShouldRasterize:YES];
[self addSublayer:whiteBackground];
[self addSublayer: blackText];
}
return self;
작동하지 않습니다
여기Text can only be drawn using sub-pixel antialiasing when it is composited into an existing opaque background at the same time that it's rasterized.
내가이 문장을 이해하는 방법이다. 텍스트는 서브 픽셀 앤티 앨리어싱을 사용하여 그려지지 않습니다.
작업 솔루션을 찾았나요? '[blackText setBackgroundColor : [NSColor whiteColor].CGColor]' –
@robmayoff 배경 색상을 whiteColor로 설정하는 것을 잊어 버렸지 만 작동하지 않습니다. 즉, 서브 픽셀이 아닌 것입니다. – alecail
나는이 순간에 나 자신을 통해 일하고있다. 위의 코드에서 적어도 하나의 문제는 blackText 레이어가 자체적으로 래스터 화하도록하는 것이고 이는 도움이되지 않습니다. 렌더링 할 때 하위 레이어를 래스터 화하도록 슈퍼 레이어에 지시해야합니다 ('setShouldRasterize :'를 설정하면됩니다.)이 문서의 일부를 읽으면 슈퍼 레이어에서 하위 레이어를 -CATextLayer는 안티 앨리어싱을 사용하여 슈퍼 레이어로 래스터 화됩니다. 다른 접근법을 찾지 못하면 나중에 테스트 할 것입니다. – Benjohn