IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等



  1. // An empty implementation adversely affects performance during animation.  
  2. - (void)drawRect:(CGRect)rect  
  3. {  
  4.     CGContextRef context = UIGraphicsGetCurrentContext();  
  5.        
  6.    
  7.        
  8.     /*NO.1画一条线 
  9.        
  10.      CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色 
  11.      CGContextMoveToPoint(context, 20, 20); 
  12.      CGContextAddLineToPoint(context, 200,20); 
  13.      CGContextStrokePath(context); 
  14.     */  
  15.    
  16.        
  17.        
  18.     /*NO.2写文字 
  19.        
  20.     CGContextSetLineWidth(context, 1.0); 
  21.     CGContextSetRGBFillColor (context, 0.5, 0.5, 0.5, 0.5); 
  22.     UIFont  *font = [UIFont boldSystemFontOfSize:18.0]; 
  23.     [@"公司:北京中软科技股份有限公司\n部门:ERP事业部\n姓名:McLiang" drawInRect:CGRectMake(20, 40, 280, 300) withFont:font]; 
  24.     */  
  25.    
  26.        
  27.     /*NO.3画一个正方形图形 没有边框 
  28.   
  29.     CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5); 
  30.     CGContextFillRect(context, CGRectMake(2, 2, 270, 270)); 
  31.     CGContextStrokePath(context); 
  32.     */  
  33.     
  34.        
  35.     /*NO.4画正方形边框 
  36.       
  37.     CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色 
  38.     CGContextSetLineWidth(context, 2.0); 
  39.     CGContextAddRect(context, CGRectMake(2, 2, 270, 270)); 
  40.     CGContextStrokePath(context); 
  41.     */  
  42.    
  43.        
  44.     /*NO.5画方形背景颜色 
  45.        
  46.     CGContextTranslateCTM(context, 0.0f, self.bounds.size.height); 
  47.     CGContextScaleCTM(context, 1.0f, -1.0f); 
  48.     UIGraphicsPushContext(context); 
  49.     CGContextSetLineWidth(context,320); 
  50.     CGContextSetRGBStrokeColor(context, 250.0/255, 250.0/255, 210.0/255, 1.0); 
  51.     CGContextStrokeRect(context, CGRectMake(0, 0, 320, 460)); 
  52.     UIGraphicsPopContext(); 
  53.     */  
  54.    
  55.     /*NO.6椭圆 
  56.        
  57.      CGRect aRect= CGRectMake(80, 80, 160, 100); 
  58.      CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0); 
  59.      CGContextSetLineWidth(context, 3.0); 
  60.      CGContextAddEllipseInRect(context, aRect); //椭圆 
  61.      CGContextDrawPath(context, kCGPathStroke); 
  62.     */  
  63.    
  64.     /*NO.7 
  65.     CGContextBeginPath(context); 
  66.     CGContextSetRGBStrokeColor(context, 0, 0, 1, 1); 
  67.     CGContextMoveToPoint(context, 100, 100); 
  68.     CGContextAddArcToPoint(context, 50, 100, 50, 150, 50); 
  69.     CGContextStrokePath(context); 
  70.     */  
  71.    
  72.     /*NO.8渐变 
  73.     CGContextClip(context); 
  74.     CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); 
  75.     CGFloat colors[] = 
  76.     { 
  77.         204.0 / 255.0, 224.0 / 255.0, 244.0 / 255.0, 1.00, 
  78.         29.0 / 255.0, 156.0 / 255.0, 215.0 / 255.0, 1.00, 
  79.         0.0 / 255.0,  50.0 / 255.0, 126.0 / 255.0, 1.00, 
  80.     }; 
  81.     CGGradientRef gradient = CGGradientCreateWithColorComponents 
  82.     (rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4)); 
  83.     CGColorSpaceRelease(rgb); 
  84.     CGContextDrawLinearGradient(context, gradient,CGPointMake 
  85.                                 (0.0,0.0) ,CGPointMake(0.0,self.frame.size.height), 
  86.                                 kCGGradientDrawsBeforeStartLocation); 
  87.      */  
  88.        
  89.       
  90.     /* NO.9四条线画一个正方形 
  91.     //画线 
  92.         UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0]; 
  93.     CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0); 
  94.        CGContextSetFillColorWithColor(context, aColor.CGColor); 
  95.     CGContextSetLineWidth(context, 4.0); 
  96.     CGPoint aPoints[5]; 
  97.     aPoints[0] =CGPointMake(60, 60); 
  98.     aPoints[1] =CGPointMake(260, 60); 
  99.     aPoints[2] =CGPointMake(260, 300); 
  100.     aPoints[3] =CGPointMake(60, 300); 
  101.     aPoints[4] =CGPointMake(60, 60); 
  102.     CGContextAddLines(context, aPoints, 5); 
  103.     CGContextDrawPath(context, kCGPathStroke); //开始画线 
  104.      */  
  105.        
  106.        
  107.        
  108.     /*  NO.10 
  109.     UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0]; 
  110.     CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0); 
  111.     CGContextSetFillColorWithColor(context, aColor.CGColor); 
  112.     //椭圆 
  113.     CGRect aRect= CGRectMake(80, 80, 160, 100); 
  114.     CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0); 
  115.     CGContextSetLineWidth(context, 3.0); 
  116.       CGContextSetFillColorWithColor(context, aColor.CGColor); 
  117.        CGContextAddRect(context, rect); //矩形 
  118.     CGContextAddEllipseInRect(context, aRect); //椭圆 
  119.     CGContextDrawPath(context, kCGPathStroke); 
  120.      */  
  121.    
  122.        
  123.        
  124.     /*  NO.11 
  125.      画一个实心的圆 
  126.    
  127.      CGContextFillEllipseInRect(context, CGRectMake(95, 95, 100.0, 100)); 
  128.     */  
  129.        
  130.        
  131.        
  132.     /*NO.12 
  133.      画一个菱形 
  134.     CGContextSetLineWidth(context, 2.0); 
  135.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  136.     CGContextMoveToPoint(context, 100, 100); 
  137.     CGContextAddLineToPoint(context, 150, 150); 
  138.     CGContextAddLineToPoint(context, 100, 200); 
  139.     CGContextAddLineToPoint(context, 50, 150); 
  140.     CGContextAddLineToPoint(context, 100, 100); 
  141.     CGContextStrokePath(context); 
  142.      */  
  143.    
  144.     /*NO.13 画矩形 
  145.     CGContextSetLineWidth(context, 2.0); 
  146.   
  147.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  148.   
  149.     CGRect rectangle = CGRectMake(60,170,200,80); 
  150.   
  151.     CGContextAddRect(context, rectangle); 
  152.       
  153.     CGContextStrokePath(context); 
  154.      */  
  155.        
  156.       
  157.     /*椭圆 
  158.     CGContextSetLineWidth(context, 2.0); 
  159.   
  160.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  161.   
  162.     CGRect rectangle = CGRectMake(60,170,200,80); 
  163.   
  164.     CGContextAddEllipseInRect(context, rectangle); 
  165.       
  166.     CGContextStrokePath(context); 
  167.      */  
  168.        
  169.     /*用红色填充了一段路径: 
  170.       
  171.     CGContextMoveToPoint(context, 100, 100); 
  172.     CGContextAddLineToPoint(context, 150, 150); 
  173.     CGContextAddLineToPoint(context, 100, 200); 
  174.     CGContextAddLineToPoint(context, 50, 150); 
  175.     CGContextAddLineToPoint(context, 100, 100); 
  176.     CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); 
  177.     CGContextFillPath(context); 
  178.     */  
  179.        
  180.     /*填充一个蓝色边的红色矩形 
  181.     CGContextSetLineWidth(context, 2.0); 
  182.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  183.     CGRect rectangle = CGRectMake(60,170,200,80); 
  184.     CGContextAddRect(context, rectangle); 
  185.     CGContextStrokePath(context); 
  186.     CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); 
  187.     CGContextFillRect(context, rectangle); 
  188.     */  
  189.        
  190.     /*画弧 
  191.      //弧线的是通过指定两个切点,还有角度,调用CGContextAddArcToPoint()绘制 
  192.     CGContextSetLineWidth(context, 2.0); 
  193.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  194.     CGContextMoveToPoint(context, 100, 100); 
  195.     CGContextAddArcToPoint(context, 100,200, 300,200, 100); 
  196.     CGContextStrokePath(context); 
  197.     */  
  198.       
  199.        
  200.     /* 
  201.     绘制贝兹曲线 
  202.     //贝兹曲线是通过移动一个起始点,然后通过两个控制点,还有一个中止点,调用CGContextAddCurveToPoint() 函数绘制 
  203.     CGContextSetLineWidth(context, 2.0); 
  204.   
  205.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  206.   
  207.     CGContextMoveToPoint(context, 10, 10); 
  208.   
  209.     CGContextAddCurveToPoint(context, 0, 50, 300, 250, 300, 400); 
  210.       
  211.     CGContextStrokePath(context); 
  212.      */  
  213.        
  214.     /*绘制二次贝兹曲线 
  215.       
  216.       CGContextSetLineWidth(context, 2.0); 
  217.   
  218.       CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  219.   
  220.       CGContextMoveToPoint(context, 10, 200); 
  221.   
  222.       CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200); 
  223.       
  224.       CGContextStrokePath(context); 
  225.      */  
  226.        
  227.     /*绘制虚线 
  228.     CGContextSetLineWidth(context, 5.0); 
  229.   
  230.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  231.   
  232.     CGFloat dashArray[] = {2,6,4,2}; 
  233.   
  234.     CGContextSetLineDash(context, 3, dashArray, 4);//跳过3个再画虚线,所以刚开始有6-(3-2)=5个虚点 
  235.       
  236.     CGContextMoveToPoint(context, 10, 200); 
  237.       
  238.     CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200); 
  239.       
  240.     CGContextStrokePath(context); 
  241.     */  
  242. /*绘制图片 
  243.     NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"]; 
  244.     UIImage* myImageObj = [[UIImage alloc] initWithContentsOfFile:imagePath]; 
  245.     //[myImageObj drawAtPoint:CGPointMake(0, 0)]; 
  246.     [myImageObj drawInRect:CGRectMake(0, 0, 320, 480)]; 
  247.   
  248.     NSString *s = @"我的小狗"; 
  249.   
  250.     [s drawAtPoint:CGPointMake(100, 0) withFont:[UIFont systemFontOfSize:34.0]]; 
  251. */  
  252.        
  253.   /* 
  254.     NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"]; 
  255.     UIImage *img = [UIImage imageWithContentsOfFile:path]; 
  256.     CGImageRef image = img.CGImage; 
  257.     CGContextSaveGState(context); 
  258.     CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height); 
  259.     CGContextDrawImage(context, touchRect, image); 
  260.     CGContextRestoreGState(context); 
  261.    */  
  262.      
  263.        
  264.     /*NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"]; 
  265.     UIImage *img = [UIImage imageWithContentsOfFile:path]; 
  266.     CGImageRef image = img.CGImage; 
  267.     CGContextSaveGState(context); 
  268.   
  269.     CGContextRotateCTM(context, M_PI); 
  270.     CGContextTranslateCTM(context, -img.size.width, -img.size.height); 
  271.   
  272.     CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height); 
  273.     CGContextDrawImage(context, touchRect, image); 
  274.     CGContextRestoreGState(context);*/  
  275.    
  276. /* 
  277.     NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"]; 
  278.     UIImage *img = [UIImage imageWithContentsOfFile:path]; 
  279.     CGImageRef image = img.CGImage; 
  280.       
  281.     CGContextSaveGState(context); 
  282.   
  283.     CGAffineTransform myAffine = CGAffineTransformMakeRotation(M_PI); 
  284.     myAffine = CGAffineTransformTranslate(myAffine, -img.size.width, -img.size.height); 
  285.     CGContextConcatCTM(context, myAffine); 
  286.   
  287.     CGContextRotateCTM(context, M_PI); 
  288.     CGContextTranslateCTM(context, -img.size.width, -img.size.height); 
  289.   
  290.     CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height); 
  291.     CGContextDrawImage(context, touchRect, image); 
  292.     CGContextRestoreGState(context); 
  293. */  
  294. }  

  1. // An empty implementation adversely affects performance during animation.  
  2. - (void)drawRect:(CGRect)rect  
  3. {  
  4.     CGContextRef context = UIGraphicsGetCurrentContext();  
  5.        
  6.    
  7.        
  8.     /*NO.1画一条线 
  9.        
  10.      CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色 
  11.      CGContextMoveToPoint(context, 20, 20); 
  12.      CGContextAddLineToPoint(context, 200,20); 
  13.      CGContextStrokePath(context); 
  14.     */  
  15.    
  16.        
  17.        
  18.     /*NO.2写文字 
  19.        
  20.     CGContextSetLineWidth(context, 1.0); 
  21.     CGContextSetRGBFillColor (context, 0.5, 0.5, 0.5, 0.5); 
  22.     UIFont  *font = [UIFont boldSystemFontOfSize:18.0]; 
  23.     [@"公司:北京中软科技股份有限公司\n部门:ERP事业部\n姓名:McLiang" drawInRect:CGRectMake(20, 40, 280, 300) withFont:font]; 
  24.     */  
  25.    
  26.        
  27.     /*NO.3画一个正方形图形 没有边框 
  28.   
  29.     CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5); 
  30.     CGContextFillRect(context, CGRectMake(2, 2, 270, 270)); 
  31.     CGContextStrokePath(context); 
  32.     */  
  33.     
  34.        
  35.     /*NO.4画正方形边框 
  36.       
  37.     CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色 
  38.     CGContextSetLineWidth(context, 2.0); 
  39.     CGContextAddRect(context, CGRectMake(2, 2, 270, 270)); 
  40.     CGContextStrokePath(context); 
  41.     */  
  42.    
  43.        
  44.     /*NO.5画方形背景颜色 
  45.        
  46.     CGContextTranslateCTM(context, 0.0f, self.bounds.size.height); 
  47.     CGContextScaleCTM(context, 1.0f, -1.0f); 
  48.     UIGraphicsPushContext(context); 
  49.     CGContextSetLineWidth(context,320); 
  50.     CGContextSetRGBStrokeColor(context, 250.0/255, 250.0/255, 210.0/255, 1.0); 
  51.     CGContextStrokeRect(context, CGRectMake(0, 0, 320, 460)); 
  52.     UIGraphicsPopContext(); 
  53.     */  
  54.    
  55.     /*NO.6椭圆 
  56.        
  57.      CGRect aRect= CGRectMake(80, 80, 160, 100); 
  58.      CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0); 
  59.      CGContextSetLineWidth(context, 3.0); 
  60.      CGContextAddEllipseInRect(context, aRect); //椭圆 
  61.      CGContextDrawPath(context, kCGPathStroke); 
  62.     */  
  63.    
  64.     /*NO.7 
  65.     CGContextBeginPath(context); 
  66.     CGContextSetRGBStrokeColor(context, 0, 0, 1, 1); 
  67.     CGContextMoveToPoint(context, 100, 100); 
  68.     CGContextAddArcToPoint(context, 50, 100, 50, 150, 50); 
  69.     CGContextStrokePath(context); 
  70.     */  
  71.    
  72.     /*NO.8渐变 
  73.     CGContextClip(context); 
  74.     CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); 
  75.     CGFloat colors[] = 
  76.     { 
  77.         204.0 / 255.0, 224.0 / 255.0, 244.0 / 255.0, 1.00, 
  78.         29.0 / 255.0, 156.0 / 255.0, 215.0 / 255.0, 1.00, 
  79.         0.0 / 255.0,  50.0 / 255.0, 126.0 / 255.0, 1.00, 
  80.     }; 
  81.     CGGradientRef gradient = CGGradientCreateWithColorComponents 
  82.     (rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4)); 
  83.     CGColorSpaceRelease(rgb); 
  84.     CGContextDrawLinearGradient(context, gradient,CGPointMake 
  85.                                 (0.0,0.0) ,CGPointMake(0.0,self.frame.size.height), 
  86.                                 kCGGradientDrawsBeforeStartLocation); 
  87.      */  
  88.        
  89.       
  90.     /* NO.9四条线画一个正方形 
  91.     //画线 
  92.         UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0]; 
  93.     CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0); 
  94.        CGContextSetFillColorWithColor(context, aColor.CGColor); 
  95.     CGContextSetLineWidth(context, 4.0); 
  96.     CGPoint aPoints[5]; 
  97.     aPoints[0] =CGPointMake(60, 60); 
  98.     aPoints[1] =CGPointMake(260, 60); 
  99.     aPoints[2] =CGPointMake(260, 300); 
  100.     aPoints[3] =CGPointMake(60, 300); 
  101.     aPoints[4] =CGPointMake(60, 60); 
  102.     CGContextAddLines(context, aPoints, 5); 
  103.     CGContextDrawPath(context, kCGPathStroke); //开始画线 
  104.      */  
  105.        
  106.        
  107.        
  108.     /*  NO.10 
  109.     UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0]; 
  110.     CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0); 
  111.     CGContextSetFillColorWithColor(context, aColor.CGColor); 
  112.     //椭圆 
  113.     CGRect aRect= CGRectMake(80, 80, 160, 100); 
  114.     CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0); 
  115.     CGContextSetLineWidth(context, 3.0); 
  116.       CGContextSetFillColorWithColor(context, aColor.CGColor); 
  117.        CGContextAddRect(context, rect); //矩形 
  118.     CGContextAddEllipseInRect(context, aRect); //椭圆 
  119.     CGContextDrawPath(context, kCGPathStroke); 
  120.      */  
  121.    
  122.        
  123.        
  124.     /*  NO.11 
  125.      画一个实心的圆 
  126.    
  127.      CGContextFillEllipseInRect(context, CGRectMake(95, 95, 100.0, 100)); 
  128.     */  
  129.        
  130.        
  131.        
  132.     /*NO.12 
  133.      画一个菱形 
  134.     CGContextSetLineWidth(context, 2.0); 
  135.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  136.     CGContextMoveToPoint(context, 100, 100); 
  137.     CGContextAddLineToPoint(context, 150, 150); 
  138.     CGContextAddLineToPoint(context, 100, 200); 
  139.     CGContextAddLineToPoint(context, 50, 150); 
  140.     CGContextAddLineToPoint(context, 100, 100); 
  141.     CGContextStrokePath(context); 
  142.      */  
  143.    
  144.     /*NO.13 画矩形 
  145.     CGContextSetLineWidth(context, 2.0); 
  146.   
  147.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  148.   
  149.     CGRect rectangle = CGRectMake(60,170,200,80); 
  150.   
  151.     CGContextAddRect(context, rectangle); 
  152.       
  153.     CGContextStrokePath(context); 
  154.      */  
  155.        
  156.       
  157.     /*椭圆 
  158.     CGContextSetLineWidth(context, 2.0); 
  159.   
  160.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  161.   
  162.     CGRect rectangle = CGRectMake(60,170,200,80); 
  163.   
  164.     CGContextAddEllipseInRect(context, rectangle); 
  165.       
  166.     CGContextStrokePath(context); 
  167.      */  
  168.        
  169.     /*用红色填充了一段路径: 
  170.       
  171.     CGContextMoveToPoint(context, 100, 100); 
  172.     CGContextAddLineToPoint(context, 150, 150); 
  173.     CGContextAddLineToPoint(context, 100, 200); 
  174.     CGContextAddLineToPoint(context, 50, 150); 
  175.     CGContextAddLineToPoint(context, 100, 100); 
  176.     CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); 
  177.     CGContextFillPath(context); 
  178.     */  
  179.        
  180.     /*填充一个蓝色边的红色矩形 
  181.     CGContextSetLineWidth(context, 2.0); 
  182.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  183.     CGRect rectangle = CGRectMake(60,170,200,80); 
  184.     CGContextAddRect(context, rectangle); 
  185.     CGContextStrokePath(context); 
  186.     CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); 
  187.     CGContextFillRect(context, rectangle); 
  188.     */  
  189.        
  190.     /*画弧 
  191.      //弧线的是通过指定两个切点,还有角度,调用CGContextAddArcToPoint()绘制 
  192.     CGContextSetLineWidth(context, 2.0); 
  193.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  194.     CGContextMoveToPoint(context, 100, 100); 
  195.     CGContextAddArcToPoint(context, 100,200, 300,200, 100); 
  196.     CGContextStrokePath(context); 
  197.     */  
  198.       
  199.        
  200.     /* 
  201.     绘制贝兹曲线 
  202.     //贝兹曲线是通过移动一个起始点,然后通过两个控制点,还有一个中止点,调用CGContextAddCurveToPoint() 函数绘制 
  203.     CGContextSetLineWidth(context, 2.0); 
  204.   
  205.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  206.   
  207.     CGContextMoveToPoint(context, 10, 10); 
  208.   
  209.     CGContextAddCurveToPoint(context, 0, 50, 300, 250, 300, 400); 
  210.       
  211.     CGContextStrokePath(context); 
  212.      */  
  213.        
  214.     /*绘制二次贝兹曲线 
  215.       
  216.       CGContextSetLineWidth(context, 2.0); 
  217.   
  218.       CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  219.   
  220.       CGContextMoveToPoint(context, 10, 200); 
  221.   
  222.       CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200); 
  223.       
  224.       CGContextStrokePath(context); 
  225.      */  
  226.        
  227.     /*绘制虚线 
  228.     CGContextSetLineWidth(context, 5.0); 
  229.   
  230.     CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
  231.   
  232.     CGFloat dashArray[] = {2,6,4,2}; 
  233.   
  234.     CGContextSetLineDash(context, 3, dashArray, 4);//跳过3个再画虚线,所以刚开始有6-(3-2)=5个虚点 
  235.       
  236.     CGContextMoveToPoint(context, 10, 200); 
  237.       
  238.     CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200); 
  239.       
  240.     CGContextStrokePath(context); 
  241.     */  
  242. /*绘制图片 
  243.     NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"]; 
  244.     UIImage* myImageObj = [[UIImage alloc] initWithContentsOfFile:imagePath]; 
  245.     //[myImageObj drawAtPoint:CGPointMake(0, 0)]; 
  246.     [myImageObj drawInRect:CGRectMake(0, 0, 320, 480)]; 
  247.   
  248.     NSString *s = @"我的小狗"; 
  249.   
  250.     [s drawAtPoint:CGPointMake(100, 0) withFont:[UIFont systemFontOfSize:34.0]]; 
  251. */  
  252.        
  253.   /* 
  254.     NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"]; 
  255.     UIImage *img = [UIImage imageWithContentsOfFile:path]; 
  256.     CGImageRef image = img.CGImage; 
  257.     CGContextSaveGState(context); 
  258.     CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height); 
  259.     CGContextDrawImage(context, touchRect, image); 
  260.     CGContextRestoreGState(context); 
  261.    */  
  262.      
  263.        
  264.     /*NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"]; 
  265.     UIImage *img = [UIImage imageWithContentsOfFile:path]; 
  266.     CGImageRef image = img.CGImage; 
  267.     CGContextSaveGState(context); 
  268.   
  269.     CGContextRotateCTM(context, M_PI); 
  270.     CGContextTranslateCTM(context, -img.size.width, -img.size.height); 
  271.   
  272.     CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height); 
  273.     CGContextDrawImage(context, touchRect, image); 
  274.     CGContextRestoreGState(context);*/  
  275.    
  276. /* 
  277.     NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"]; 
  278.     UIImage *img = [UIImage imageWithContentsOfFile:path]; 
  279.     CGImageRef image = img.CGImage; 
  280.       
  281.     CGContextSaveGState(context); 
  282.   
  283.     CGAffineTransform myAffine = CGAffineTransformMakeRotation(M_PI); 
  284.     myAffine = CGAffineTransformTranslate(myAffine, -img.size.width, -img.size.height); 
  285.     CGContextConcatCTM(context, myAffine); 
  286.   
  287.     CGContextRotateCTM(context, M_PI); 
  288.     CGContextTranslateCTM(context, -img.size.width, -img.size.height); 
  289.   
  290.     CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height); 
  291.     CGContextDrawImage(context, touchRect, image); 
  292.     CGContextRestoreGState(context); 
  293. */  
  294. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值