我想知道如何再现我们可以在几个mac和iPhone应用程序中看到的图像效果,所有这些效果都是从黑白图片开始的:-在iPhone上的UiTabbar中,黑白图片如何在被选中时变成蓝色渐变-在Mac的Twitter中,我们可以看到几种效果(发光,斜面,...)
欢迎对此主题的任何帮助。:)
编辑:我感兴趣的是这些对MAC的影响,而不是对iPhone的影响。
发布于 2011-02-22 13:53:02
查看苹果的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);
发布于 2011-02-06 19:42:13
我不认为有必要绘制这些图像,因为你可以用其他软件(photoshop,pixelmator等)获得相同的图像。为什么?因为(按钮的)内容不会改变,也不会调整大小,所以图像看起来很好看,也是最简单的方式。
如果你想学习如何使用Quartz绘图,在Apple dev center和/或Xcode中有很多文档和示例。
这是Matt Gallagher最近的一个教程:Advanced drawing using AppKit
https://stackoverflow.com/questions/4912791
复制相似问题