background image

iOS

——CoreGraphics 简单绘图

一、导入

coreGraphics.framework

二、绘制图形

1、绘制矩形

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// 绘制矩形

- (

void

)drawRectangle {

 
    

// 定义矩形的 rect

    CGRect rectangle = CGRectMake(100, 290, 120, 25);
     
    

// 获取当前图形,视图推入堆栈的图形,相当于你所要绘制图形的图纸

    CGContextRef ctx = UIGraphicsGetCurrentContext();
     
    

// 在当前路径下添加一个矩形路径

    CGContextAddRect(ctx, rectangle);
     
    

// 设置试图的当前填充色

    CGContextSetFillColorWithColor(ctx, [UIColor blackColor].CGColor);
     
    

// 绘制当前路径区域

    CGContextFillPath(ctx);
}

2、绘制椭圆

1
2
3
4
5
6
7
8
9

// 绘制椭圆

- (

void

)drawEllipse {

 
    

// 获取当前图形,视图推入堆栈的图形,相当于你所要绘制图形的图纸

    CGContextRef ctx = UIGraphicsGetCurrentContext();
     
    

// 定义其 rect

    CGRect rectangle = CGRectMake(10, 100, 300, 280);
     

                   找软件资料,就到一览软件文库

http://wk.yl1001.com/rj/