首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >具有核心图形的图像效果

具有核心图形的图像效果
EN

Stack Overflow用户
提问于 2011-02-06 18:43:20
回答 2查看 3.8K关注 0票数 5

我想知道如何再现我们可以在几个mac和iPhone应用程序中看到的图像效果,所有这些效果都是从黑白图片开始的:-在iPhone上的UiTabbar中,黑白图片如何在被选中时变成蓝色渐变-在Mac的Twitter中,我们可以看到几种效果(发光,斜面,...)

欢迎对此主题的任何帮助。:)

编辑:我感兴趣的是这些对MAC的影响,而不是对iPhone的影响。

EN

回答 2

Stack Overflow用户

发布于 2011-02-22 13:53:02

查看苹果的QuartzDemo示例项目。QuartzClipping类向您展示了如何使用剪辑和蒙版。这是我根据这个项目得出的结论。

代码语言:javascript
运行
复制
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);
票数 3
EN

Stack Overflow用户

发布于 2011-02-06 19:42:13

我不认为有必要绘制这些图像,因为你可以用其他软件(photoshop,pixelmator等)获得相同的图像。为什么?因为(按钮的)内容不会改变,也不会调整大小,所以图像看起来很好看,也是最简单的方式。

如果你想学习如何使用Quartz绘图,在Apple dev center和/或Xcode中有很多文档和示例。

这是Matt Gallagher最近的一个教程:Advanced drawing using AppKit

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4912791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档