체크 아웃 애플의 QuartzDemo 샘플 프로젝트 :
이 매트 갤러거에서 최근의 튜토리얼입니다. QuartzClipping 클래스는 클리핑 및 마스킹 작업 방법을 보여줍니다. 그 프로젝트를 기반으로 내가 알아 낸 것입니다.
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage *img = [UIImage imageNamed:@"at.png"];
CGImageRef alphaImage = CGImageRetain(img.CGImage);
UIImage *backgroundImg = [UIImage imageNamed:@"gradientBackground.png"]; // background image for normal state
CGImageRef image = CGImageRetain(backgroundImg.CGImage);
CGFloat height = self.bounds.size.height;
CGContextTranslateCTM(context, 0.0, height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetRGBFillColor(context, 0.129, 0.129, 0.129, 1.0);
CGContextFillRect(context, self.bounds);
CGContextSaveGState(context);
CGContextClipToMask(context, CGRectMake(100.0, height - 150.0, img.size.width, img.size.height), alphaImage);
CGContextDrawImage(context, CGRectMake(100.0 - (backgroundImg.size.width-img.size.width)/2,
height - 150 - (backgroundImg.size.height-img.size.height)/2,
backgroundImg.size.width,
backgroundImg.size.height), image);
CGContextRestoreGState(context);
UIImage *backgroundImg2 = [UIImage imageNamed:@"TabBarItemSelectedBackground.png"]; // background image for selected state
CGImageRef image2 = CGImageRetain(backgroundImg2.CGImage);
CGContextSaveGState(context);
CGContextClipToMask(context, CGRectMake(180.0, height - 150.0, img.size.width, img.size.height), alphaImage);
CGContextDrawImage(context, CGRectMake(180.0 - (backgroundImg2.size.width-img.size.width)/2,
height - 150.0 - (backgroundImg2.size.height-img.size.height)/2,
backgroundImg2.size.width,
backgroundImg2.size.height), image2);
CGContextRestoreGState(context);
CGImageRelease(image);
CGImageRelease(alphaImage);
CGImageRelease(image2);
질문은 포토샵을 사용하지 않고 코드에서 가져 오는 방법이었습니다. 그리고 아니요, 이런 종류의 효과에 대한 많은 문서가 없습니다. 튜토리얼에 관해서는 Matt Gemmell이 작성한 것이 아닙니다 (누가 코드를 생성합니까) –
링크 된 튜토리얼은 Matt Gemmell이 아닌 Matt Gallagher가 작성했습니다. –
죄송합니다. 이름을 수정했습니다. – nacho4d