IOS开发(83)之为形状增加阴影
来源:互联网 发布:电脑自带编程软件 编辑:程序博客网 时间:2024/04/28 00:53
1 前言
使用 CGContextSetShadow 过程,为绘制在图形环境上的形状应用阴影。
CGContextSetShadowWithColor 过程:这个过程接受的参数和 CGContextSetShadow 完全相同,不过加了一个 CGColorRef 类型的参数,用于设 置阴影的颜色。
2 代码实例
ZYViewControllerView.m
-(void)drawRect:(CGRect)rect{ [self drawRectAtTopOfScreen]; //由于第一个矩形画的时候已经有了阴影,所以就算第二个矩形绘图时候没有设置依然有阴影 [self drawRectAtBottomOfScreen];}- (void) drawRectAtTopOfScreen{ CGContextRef currentContext = UIGraphicsGetCurrentContext(); //用灰色设置背景颜色 /*第二个参数:阴影的位移,由 CGSize 类型值指定,从每个形状要应用阴影的右下部分开始。位移的 x 值越大,形状 右边的阴影就扩散得越远。位移的 y 值越大,下部的阴影就越低。 第三个参数:阴影的模糊值,以浮点值(CGFloat)来指定。指定 0.0f 将导致阴影成为固态形状。这个值越高,阴影就越 模糊。我们很快能看到例子。 */ CGContextSetShadowWithColor(currentContext,CGSizeMake(10.0f, 10.0f), 20.0f,[[UIColor grayColor] CGColor]); /* Create the path first. Just the path handle. */ CGMutablePathRef path = CGPathCreateMutable(); CGRect firstRect = CGRectMake(55.0f, 60.0f,150.0f, 150.0f); CGPathAddRect(path,NULL, firstRect); CGContextAddPath(currentContext, path); [[UIColor colorWithRed:0.20f green:0.60f blue:0.80f alpha:1.0f] setFill]; CGContextDrawPath(currentContext, kCGPathFill); CGPathRelease(path);}- (void) drawRectAtBottomOfScreen{ CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGMutablePathRef secondPath = CGPathCreateMutable(); CGRect secondRect = CGRectMake(150.0f, 250.0f, 100.0f,100.0f); CGPathAddRect(secondPath, NULL,secondRect); CGContextAddPath(currentContext, secondPath); [[UIColor purpleColor] setFill]; CGContextDrawPath(currentContext, kCGPathFill); CGPathRelease(secondPath);}
运行结果
3 结语
以上是所有内容,希望对大家有所帮助。
Demo代码实例:http://download.csdn.net/detail/u010013695/5375751
- IOS开发(83)之为形状增加阴影
- 为文字增加阴影
- iOS开发之阴影效果
- 为ToolBar增加阴影特效
- iOS开发之UI控件阴影效果
- iOS 开发 控件阴影
- ios为UIView设置阴影
- iOS-为视图添加阴影
- iOS为视图添加阴影
- ios开发之uiTableView增加搜索框
- IOS笔记之 控件 阴影
- iOS-CoreAnimation之制作阴影
- iOS 开发技巧--快速设置imageView形状
- IOS开发(55)之为普通App添加Storyboard
- IOS开发(55)之为普通App添加Storyboard
- Sprite添加阴影摇摆动画(Unity3D开发之九)
- 前端学习之为边框添加阴影
- iOS开发点滴-添加阴影效果
- Android,ListView的使用
- 8瓶酒一瓶有毒,用人测试。每次测试结果8小时后才会得出,而你只有8个小时的时间。
- HDU 1535 Invitation Cards(有向图单源最短路径+SPFA)
- FCKeditor的js验证以及FCKeditor内容是否为空判断
- java clone 中的浅复制和深复制
- IOS开发(83)之为形状增加阴影
- ORACLE dblink数据库连接 使用简单字符串方式
- 解读vs2003、vs2005、vs2008开发Windows CE环境、默认SDK开发包及测试
- js判断FCKeditor内容是否为空
- [Android] 获取Android设备的唯一识别码|设备号|序号|UUID
- MFC中变量的命名方法
- DBhelper数据操作类
- 我的失恋
- 失业的程序员(十二):潜意识的智商