drawRect简单的绘图Demo

-(void)drawRect:(CGRect)rect{

    //[self drawline ];

    //[self drawball];

    //[self drawxunLine];

    //[self drawxuboll];

    //绘制上下文方式画一条线

    [self drawlineGrap];



}

-(void)drawxuboll{

    //1 获取上下文

    CGContextRef ref = UIGraphicsGetCurrentContext();

    //路径

    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, 50, 90)];

    //颜色边线

    [[UIColor redColor]setStroke];

    //填充颜色

    [[UIColor yellowColor]setFill];

    //线宽

    CGContextSetLineWidth(ref, 4);

    //虚线

    CGFloat lengths[] = {7,11};

    CGContextSetLineDash(ref, 0, lengths, 2);

    //将路径添加到上下文中

    CGContextAddPath(ref, path.CGPath);

    //end:将上下文渲染

    CGContextDrawPath(ref, kCGPathFillStroke);

}

-(void)drawxunLine{

    //另外一中画横线的方法

    //创建上下文

    CGContextRef ref = UIGraphicsGetCurrentContext();

    //创建路径

    UIBezierPath *path1 = [UIBezierPath bezierPath];

    //创建七点

    [path1 moveToPoint:CGPointMake(1, 0)];

    //增加一条线段到某点

    [path1 addLineToPoint:CGPointMake(99, 99)];

    //颜色

    [[UIColor redColor]set];

    //线宽

    CGContextSetLineWidth(ref, 4);

    //虚线

    CGFloat lengths[] = {4,2};

    CGContextSetLineDash(ref, 0, lengths, 2);

    //将路径关联到上下文

    CGContextAddPath(ref, path1.CGPath);

    //end : 渲染

    // CGContextStrokePath(ref); //stroke

    CGContextDrawPath(ref, kCGPathFillStroke);//

    


}

-(void)drawball{

    //宽高相等为圆形 , 宽高不相等为 椭圆形

    UIBezierPath *path  = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(88, 0, 88, 108)];

    ///颜色set = fill+stroke 同时执行

    //  [[UIColor redColor]set];

    // stroke绘制外边框的颜色

    [[UIColor redColor]setStroke];

    //fill 绘制图形里边的填充颜色

    [[UIColor yellowColor]setFill];;

    path.lineWidth = 5;

    //绘制

    [path stroke];

    [path fill];

    

    


}

-(void)drawline{

    //绘制一条横线

    //用贝塞尔曲线类(路径)

    UIBezierPath *path =[UIBezierPath bezierPath];

    //创建起点坐标

    [path  moveToPoint:CGPointMake(0, 0)];

    //增加一条线段到某个点

    [path addLineToPoint:CGPointMake(33, 33)];

    //设置先段的颜色

    

    [[UIColor redColor] set];

    //设置线宽

    path.lineWidth =4;

    //end: 绘制上去

    [path stroke];

    UIBezierPath *path1 = [UIBezierPath bezierPath];

    [path1 moveToPoint:CGPointMake(20, 20)];

    [path1  addLineToPoint:CGPointMake(100, 100)];

    [path1  addLineToPoint:CGPointMake(40, 120)];

    [path1 closePath];

    [[UIColor orangeColor]set];

    path1.lineWidth = 10;

    [path1 stroke];

    

}



-(void)drawlineGrap{

    CGContextRef ref = UIGraphicsGetCurrentContext();

    UIBezierPath *path = [UIBezierPath bezierPath];

    [path moveToPoint:CGPointMake(0, 0)];

    [path addLineToPoint:CGPointMake(30, 30)];

    [[UIColor blueColor]set];

    

    CGContextSetLineWidth(ref, 4);

    CGContextAddPath(ref, path.CGPath);

    CGContextDrawPath(ref, kCGPathFillStroke);

}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值