zoukankan      html  css  js  c++  java
  • iOS 绘图(虚线、椭圆)

    #pragma  画虚线 

      UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 640)];

        imageView1.backgroundColor = [UIColor redColor];

        [self.view addSubview:imageView1];

     

        UIGraphicsBeginImageContext(imageView1.frame.size);   //开始画线

        CGFloat lengths[] = {10,4};  //10个点,空4个点

        CGContextRef line = UIGraphicsGetCurrentContext(); //设置上下文

        CGContextSetStrokeColorWithColor(line, [UIColor blackColor].CGColor);

        

        CGContextSetLineDash(line, 0, lengths, 2);  //画虚线

        CGContextMoveToPoint(line, 100.0, 10.0);    //开始画线,设置X,Y的起点位置

        CGContextAddLineToPoint(line, 300.0,550.0); //线终点的X,Y位置

        CGContextStrokePath(line); //填充

        

        imageView1.image = UIGraphicsGetImageFromCurrentImageContext();

     

     

    #pragma 画椭圆

        UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 640)];

        [self.view addSubview:imageView1];

        UIGraphicsBeginImageContext(imageView1.frame.size);   //开始画线

        [imageView1.image drawInRect:CGRectMake(0, 0, imageView1.frame.size.width, imageView1.frame.size.height)];

        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //设置线条终点形状

        CGFloat lengths[] = {10,10};

        CGContextRef ellipse = UIGraphicsGetCurrentContext();

        CGContextSetStrokeColorWithColor(ellipse, [UIColor redColor].CGColor);

        CGContextSetLineDash(ellipse, 0, lengths, 2);  //画虚线园

        CGRect rectangle = CGRectMake(0,0,200,80);

        CGContextAddEllipseInRect(ellipse,rectangle);

        CGContextStrokePath(ellipse);

        imageView1.image = UIGraphicsGetImageFromCurrentImageContext();

     

  • 相关阅读:
    异常 中断 陷阱
    关于delete字符串 需不需要加 [ ]
    关于联合体输出的问题(是否小端模式)
    String reorder
    数据库 ---5 索引 创建用户及授权 数据备份
    数据库 --- 4 多表查询 ,Navicat工具 , pymysql模块
    数据库 --- 3 行(记录)操作 单表查询
    数据库 --- 2 库 ,表
    数据库 --- 1 初始 数据库
    并发 --- 5 线程的其他方法 线程队列 线程池 协程
  • 原文地址:https://www.cnblogs.com/i0ject/p/4094507.html
Copyright © 2011-2022 走看看