#import "ViewController.h"

#import "DrawView.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

- (IBAction)doTouchButton:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

DrawView *view=[[DrawView alloc]initWithFrame:self.view.frame];

view.backgroundColor =[UIColor whiteColor];

//    [self.view addSubview:view];//去掉注释后,显示绘图

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (IBAction)doTouchButton:(id)sender {

//小鸡走五角星

CGMutablePathRef startPath=CGPathCreateMutable();//创建一个路径

CGPathMoveToPoint(startPath, NULL, 160, 100);

CGPathAddLineToPoint(startPath, NULL, 220, 280);

CGPathAddLineToPoint(startPath, NULL, 60, 170);

CGPathAddLineToPoint(startPath, NULL, 260, 170);

CGPathAddLineToPoint(startPath, NULL, 100, 280);

CGPathAddLineToPoint(startPath, NULL, 160, 100);

CAKeyframeAnimation *animation=[CAKeyframeAnimation  animationWithKeyPath:@"position"];

animation.duration=5.0;//设置动画时间

[animation setPath:startPath];//设置路径

[_imageView.layer addAnimation:animation forKey:@"position"];

}

@end

/********************************************************/

//

//  DrawView.h

//  IOS绘图0817

//

//  Created by 张艳锋 on 15/8/17.

//  Copyright (c) 2015年 张艳锋. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface DrawView : UIView

@end

/********************************************************/

//

#import "DrawView.h"

@implementation DrawView

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

// Drawing code

CGContextRef context=UIGraphicsGetCurrentContext();//绘制图形上下文

CGContextSetLineWidth(context, 2.0);//设直线条宽度

[[UIColor redColor]setStroke];//设置线条颜色

CGPoint point1=CGPointMake(160, 100);//上

CGPoint point2=CGPointMake(60, 170);//左

CGPoint point3=CGPointMake(260, 170);//右

CGPoint point4=CGPointMake(100, 280);//下左

CGPoint point5=CGPointMake(220, 280);//下右

CGContextMoveToPoint(context, point1.x, point1.y);

CGContextAddLineToPoint(context, point5.x, point5.y);

CGContextAddLineToPoint(context, point2.x, point2.y);

CGContextAddLineToPoint(context, point3.x, point3.y);

CGContextAddLineToPoint(context, point4.x, point4.y);

//    CGContextAddLineToPoint(context, point1.x, point1.y);

CGContextClosePath(context);//闭合区域函数

//    CGContextStrokePath(context);

[[UIColor orangeColor]setFill];//设置填充颜色

CGContextDrawPath(context, kCGPathFillStroke);//进行描绘函数

//    kCGPathFill,//无边线,包围区域全部填充

//    kCGPathEOFill,//无边线,包围区域重合部分不填充

//    kCGPathStroke,//只显边线,不填充

//    kCGPathFillStroke,//填充又显示边线

//    kCGPathEOFillStroke//有边线包围区域重合部分不填充

//正方形

//CGContextAddRect矩形

//CGContextAddEllipseInRect椭圆 圆

CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);//红色

CGContextSetLineWidth(context, 1.5);

CGContextAddRect(context, CGRectMake(100, 60, 80, 80));//正方形

CGContextAddRect(context, CGRectMake(200, 60, 100, 200));//矩形

CGContextAddEllipseInRect(context,CGRectMake(50, 100, 100, 60));//椭圆

CGContextAddEllipseInRect(context,CGRectMake(50, 200, 100, 100));//圆

CGContextStrokePath(context);

}

IOS绘图的更多相关文章

  1. 论文第4章:iOS绘图平台的实现

    面向移动设备的矢量绘图平台设计与实现 Design and Implementation of Mobile Device-oriented Vector Drawing Platform 引用本论文 ...

  2. iOS绘图教程 (转,拷贝以记录)

    本文是<Programming iOS5>中Drawing一章的翻译,考虑到主题完整性,在翻译过程中我加入了一些书中没有涉及到的内容.希望本文能够对你有所帮助. 转自:http://www ...

  3. iOS绘图教程

    本文是<Programming iOS5>中Drawing一章的翻译,考虑到主题完整性,翻译版本中加入了一些书中未涉及到的内容.希望本文能够对你有所帮助.(本文由海水的味道翻译整理,转载请 ...

  4. iOS绘图框架CoreGraphics分析

    由于CoreGraphics框架有太多的API,对于初次接触或者对该框架不是十分了解的人,在绘图时,对API的选择会感到有些迷茫,甚至会觉得iOS的图形绘制有些繁琐.因此,本文主要介绍一下iOS的绘图 ...

  5. iOS绘图系统UIKit与Core Graphics

    概述 iOS主要的绘图系统有UIKit,Core Graphics,Core Animation,Core Image,Open GL等,本片博文主要介绍UIKit与Core Graphics的绘图系 ...

  6. IOS 绘图教程Quartz2D

    http://www.cocoachina.com/industry/20140115/7703.html http://www.cnblogs.com/wendingding/p/3803020.h ...

  7. ios绘图时的坐标处理

    在iOS中,进行绘图操作时,一般主要是在UIView:drawRect中调用 UIGraphicsBeginImageContextWithOptions等一系列函数,有时候直接画图就行,比如UIIm ...

  8. iOS绘图UIBezierPath 和 Core Graphics框架

    前言 iOS系统本身提供了两套绘图的框架,即UIBezierPath 和 Core Graphics.而前者所属UIKit,其实是对Core Graphics框架关于path的进一步封装,所以使用起来 ...

  9. iOS绘图—— UIBezierPath 和 Core Graphics

    前言 iOS系统本身提供了两套绘图的框架,即UIBezierPath 和 Core Graphics.而前者所属UIKit,其实是对Core Graphics框架关于path的进一步封装,所以使用起来 ...

随机推荐

  1. Ubantu下FTP服务器资源进行控制

    在FTP服务器的管理中无论对本地用户还是匿名用户,对于FTP服务器资源的使用都需要进行控控制, 避免由于负担过大造成FTP服务器运行异常, 可以添加以下配置项对FTP客户机使用FTP服务器资源进行控制 ...

  2. CentOS 6.4 离线安装 Cloudera 5.7.1 CDH 5.7.1

    因为项目开发需要要在本地组建一个Hadoop/Spark集群,除了Hadoop/Spark还要同时安装多个相关的组件,如果一个个组件安装配置,对于一个由多台服务器组成的集群来说,工作量是巨大的. 所以 ...

  3. sql server 中将由逗号“,”分割的一个字符串,转换为一个表,并应用与 in 条件

    ,,) 这样的语句和常用,但是如果in 后面的 1,2,3是变量怎么办呢,一般会用字符串连接的方式构造sql语句 string aa="1,2,3"; string sqltxt= ...

  4. 自定义带有uitableview的alertview对话框

    #import <UIKit/UIKit.h> typedef void(^MyCompleteHandler) (NSString *selectString); @interface ...

  5. label添加手势(触摸改变其背景颜色)

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...

  6. TCP/IP协议原理与应用笔记22:静态和动态路由选择

    1. 静态路由选择: Static routing 管理员手工设置 管理员手动更新 不能保证路由的一致性和及时性 管理性强 没有路由开销 小型.变化缓慢网络 2. 动态路由选择 Dynamic rou ...

  7. Jqeury获取table当前行与指定列

    今天遇到了一个Jqeury获取table当前行与指定列的问题: 大概的实现要求是一个页面中,上面有几个input输入框,下面有一个table,当在输入框中输入内容的时候,点击添加按钮的时候,在下面ta ...

  8. 重构4-Push Down Method(方法下移)

    我们介绍了将方法迁移到基类以供多个子类使用的上移方法重构,今天我们来看看相反的操作.重构前的代码如下: public abstract class Animal { public void Bark( ...

  9. js 回车键 跳转到下一个输入框

    window.document.onkeydown(){ if(event.keyCode==13) event.keyCode=9; }

  10. 怒刷DP之 HDU 1176

    免费馅饼 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status  ...