IOS基础之绘图函数的使用

IOS基础之绘图函数的使用

在这里插入图片描述

//
//  HMView.m
//  25-绘图步骤
//
//  Created by 鲁军 on 2021/2/14.
//

#import "HMView.h"

@implementation HMView

- (void)drawRect:(CGRect)rect {
    [self test11];
    //NSLog(@"%@",NSStringFromCGRect(rect));
    //{{0, 0}, {300, 300}}  打印的是当前view的bounds
    //[self setNeedsDisplayInRect:rect];
}
-(void)test11{
    //C hua yuan
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextAddArc(ctx, 150, 150, 100, 0, 2*M_PI, 1);
    CGContextStrokePath(ctx);
}

-(void)test10{
    //使用纯画圆函数 绘制圆形
    //ArcCenter 圆心
    //radius 半径
    //startAngle 起始位置
    //endAngle 结束位置
    //clockwise 是否是顺时针 1 逆时针。0。顺时针
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:2*M_PI - M_PI_2 clockwise:YES];
    [path stroke];
}
-(void)test9{
    //C 画椭圆
    CGContextRef ctx=UIGraphicsGetCurrentContext();
    CGContextAddEllipseInRect(ctx, CGRectMake(10, 10, 150, 100));
    CGContextStrokePath(ctx);
}
-(void)test8{
    //画椭圆
   // UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 100)];
   // [path stroke];
    //画圆
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];
    [path stroke];
}

-(void)test7{
    //带圆角的矩形的绘画
    //UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 100, 100, 100) cornerRadius:10];
    //[path stroke];
    //画圆
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 100, 100, 100) cornerRadius:50];
    [path stroke];
}
-(void)test6{
    //绘制矩形
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(100, 100, 100, 100)];
    [path stroke];
    
}

-(void)test5{
    // chun OC fang shi
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(50, 50)];
    [path addLineToPoint:CGPointMake(100, 100)];
    [path stroke];
}
-(void)test4{
    //c + oc
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //拼接路径(c)
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 50, 50);
    CGPathAddLineToPoint(path, NULL, 100, 100);
    //拼接路径(oc)
    UIBezierPath *path1 = [UIBezierPath bezierPathWithCGPath:path];
    [path1 addLineToPoint:CGPointMake(150, 50)];
    //3.路径添加当前的上下文
    CGContextAddPath(ctx, path1.CGPath);
    //4渲染
    CGContextStrokePath(ctx);
}
-(void)test3{
    //oc + c
    // 1 获取 当前上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //拼接路径
    UIBezierPath *path = [[UIBezierPath alloc] init];
    [path moveToPoint:CGPointMake(50, 50)];
    [path addLineToPoint:CGPointMake(100, 250)];
    //3.路径添加当前的上下文
    CGContextAddPath(ctx, path.CGPath);
    CGContextStrokePath(ctx);
}
-(void)test2{
    //C的
    // 1 获取 当前上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //2 拼接路径。
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 50, 50);
    CGPathAddLineToPoint(path, NULL, 100, 200);
    //3.路径添加当前的上下文
    CGContextAddPath(ctx, path);
    //4渲染
    CGContextStrokePath(ctx);
}
-(void)test1{
     // 1 获取 当前上下文
      CGContextRef ctx = UIGraphicsGetCurrentContext();
     //2 拼接路径。 同时把路径添加当前的上下文
     CGContextMoveToPoint(ctx, 50, 50); //起点
     CGContextAddLineToPoint(ctx, 100, 100);  //终点
     CGContextAddLineToPoint(ctx, 150, 50);  //终点
     CGContextMoveToPoint(ctx, 50, 200); //起点
     CGContextAddLineToPoint(ctx, 200, 200);  //终点
     //3。渲染
     CGContextStrokePath(ctx);
}
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值