CGLayer로 작업을 수행 할 수 있습니다.
기존 코드를 사용하여 CGLayer에 문자 (또는 다른 것)를 그릴 수 있어야합니다.
CGContextSaveGState(UIGraphicsGetCurrentContext()) ...
CGContextClipToMask(UIGraphicsGetCurrentContext(), self.frame, anAlphaMask);
그래서 그냥 그라데이션의 이미지에 마스크, 또는 무엇이든 작동 : 이제 당신이 사용할 수있는 좋은 마스크를
// first, make a CGLayer...
CGLayerRef yourDrawingPad =
CGLayerCreateWithContext(UIGraphicsGetCurrentContext(),etc..
CGContextRef yourRef = CGLayerGetContext(yourDrawingPad);
// now, draw to yourRef .. draw your various typography (or anything)
// use your current drawing code.
// all done drawing, now make an image mask...
UIGraphicsBeginImageContext(CGLayerGetSize(yourDrawingPad));
CGContextRef temp = UIGraphicsGetCurrentContext();
CGContextDrawLayerAtPoint(temp, CGPointZero, yourDrawingPad);
CGImageRef anAlphaMask = CGBitmapContextCreateImage(temp);
UIGraphicsEndImageContext();
:
여기에 일부 거친 코드입니다.
(알만 : 아마도 당신은 비트 맵 이미지를 오프 스크린 구성해야합니다 후 마스크로 그 사용)
각주 : 당신이 거꾸로 칠해야합니다 가능성이 높다 잊지 마세요! 다행히도 그것은 다루기 쉽습니다. 그것이 말하는 어디 상태 저장 그리기 전에 "지금 yourRef 그릴 '과 두 줄의 코드를 추가
CGContextTranslateCTM(refForMask, 0, self.frame.size.height);
CGContextScaleCTM(refForMask, 1.0, -1.0);
는
이상한. 나는 코멘트를 게시하고 실종되었다. 어쩌면 내가 제대로 추가하지 않았다. 그래서 여기 다시 있습니다. 나는 두 가지 접근법을 시도 할 것이다. 도와 주셔서 감사합니다. – Ernesto