iOS有关图片处理的总结 (五)------iOS绘图(UIBezierPath)

来源:互联网 发布:mysql查看数据库编码 编辑:程序博客网 时间:2024/06/06 00:01


        iOS绘图的方法有很多种,最近用过画直线,今天我们来总结一下。

        首先给大家介绍一个类UIBezierPath,UIBerzierPath类可以创建矢量路径,这个类是CoreGrapice框架关于path的一个封装,UIBezierPath对象是CGPathRef数据类型封装,一个UIBezierPath对象定义一个完整的路径包括一个或者多个subpaths,包括直线和曲线。

      先看看用UIBerzierPath创建一条直线:

- (void)drawRect:(CGRect)rect{    UIColor *color = [UIColor yellowColor];    [color set]; //设置线条颜色    UIBezierPath* aPath = [UIBezierPath bezierPath];    aPath.lineWidth = 0.5;    aPath.lineCapStyle = kCGLineCapRound; //线条拐角    aPath.lineJoinStyle = kCGLineCapRound; //终点处理    // Set the starting point of the shape.    [aPath moveToPoint:CGPointMake(_num, 0.0)];    // Draw the lines    [aPath addLineToPoint:CGPointMake(_num, 40.0)];    [aPath closePath];    [aPath stroke];//Draws line 根据坐标点连线}

 // Set the render colors

用这两个方法可以设置边和填充图形的颜色

    [[UIColor blackColor] setStroke];    [[UIColor whiteColor] setFill];


[aPath stroke] 这里是将坐标练成线,如果三个点以上的会出现一个图行,用这个方法会连接成一个图形是线的连接,

如果用  [aPath fill]就会填充这个图像。


这里的Num是一个随机数,可以用作画图,只是在X的坐标不一样。

利用UIBezierPath画圆弧:

     UIBezierPath *path=[UIBezierPath bezierPath];    [path addArcWithCenter:CGPointMake(100, 100) radius:60 startAngle:0 endAngle:360 clockwise:YES];

还有一点值得注意的是

UIBezierPath 在UIView中进行绘图.




0 0