ios-矩形-圆角矩形-椭圆-圆形的绘制

来源:互联网 发布:asp淘宝客源码 编辑:程序博客网 时间:2024/05/17 01:26

画一个矩形

//创建路径    UIBezierPath * path=[UIBezierPath bezierPathWithRect:CGRectMake(20, 20, 80, 80)];    //渲染    [path stroke];//也可以直接这样  [[UIBezierPath bezierPathWithRect:CGRectMake(20, 20, 80, 80)] stroke];
画一个圆角矩形

UIBezierPath * path=[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 20, 80, 80) cornerRadius:30];    //渲染    [path stroke];

OC的方式画一个椭圆

UIBezierPath * path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 70, 140)];    [path stroke];
C语言画一个椭圆

 CGContextRef ctx=UIGraphicsGetCurrentContext();    //拼接路径    CGContextAddEllipseInRect(ctx, CGRectMake(0, 0, 70, 140));    //渲染    CGContextStrokePath(ctx);

OC的方式通过圆弧画圆

//    ArcCenter表示圆心//    radius表示半径//    startAngle表示的是起始的位置如果为0就是三点钟方向 M_PI就是9点钟方向//    endAngle 表示结束的位置//     clockwise表示是否是顺时针来画    UIBezierPath * path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(60, 60) radius:60 startAngle:0 endAngle:2*M_PI clockwise:YES];    [path stroke];
C语言通过圆弧画圆如果画的是0-M_PI和OC的从0-M_PI是相反的,在Mac电脑上就是一样的,在ios下是和上面画的相反的。其实就是顺时针和逆时针在ios在是反着的。

    CGContextRef  ctx=UIGraphicsGetCurrentContext();    //拼接路径    CGContextAddArc(ctx,50, 50, 50, 0, 2*M_PI, 1);    //渲染    CGContextStrokePath(ctx);

阅读全文
0 0