成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone繪圖關于QuartZ中繪制Line案例

移動開發 iOS
iPhone繪圖關于QuartZ中繪制Line案例是本文要介紹的內容,主要介紹了如何在QuartZ中繪制Line的內容,來看詳細內容。

iPhone繪圖關于QuartZ繪制Line案例是本文要介紹的內容,主要介紹了如何在QuartZ繪制Line的內容,來看詳細內容。下面的代碼和例子都是從官方的Quartz Demo中截取的,在此在寫下以便以后用到。

1.基本的劃線代碼。

  1. CGContextRef context = UIGraphicsGetCurrentContext();  
  2. // Drawing lines with a white stroke color  
  3. CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);  
  4. // Draw them with a 2.0 stroke width so they are a bit more visible.  
  5. CGContextSetLineWidth(context, 2.0);  
  6. // Draw a single line from left to right  
  7. CGContextMoveToPoint(context, 10.0, 30.0);  
  8. CGContextAddLineToPoint(context, 310.0, 30.0);  
  9. CGContextStrokePath(context);  
  10. // Draw a connected sequence of line segments  
  11. CGPoint addLines[] =  
  12. {  
  13. CGPointMake(10.0, 90.0),  
  14. CGPointMake(70.0, 60.0),  
  15. CGPointMake(130.0, 90.0),  
  16. CGPointMake(190.0, 60.0),  
  17. CGPointMake(250.0, 90.0),  
  18. CGPointMake(310.0, 60.0),  
  19. };  
  20. // Bulk call to add lines to the current path.  
  21. // Equivalent to MoveToPoint(points[0]); for(i=1; i<count; ++i) AddLineToPoint(points[i]);  
  22. CGContextAddLines(context, addLines, sizeof(addLines)/sizeof(addLines[0]));  
  23. CGContextStrokePath(context);  
  24. // Draw a series of line segments. Each pair of points is a segment  
  25. CGPoint strokeSegments[] =  
  26. {  
  27. CGPointMake(10.0, 150.0),  
  28. CGPointMake(70.0, 120.0),  
  29. CGPointMake(130.0, 150.0),  
  30. CGPointMake(190.0, 120.0),  
  31. CGPointMake(250.0, 150.0),  
  32. CGPointMake(310.0, 120.0),  
  33. };  
  34. // Bulk call to stroke a sequence of line segments.  
  35. // Equivalent to for(i=0; i<count; i+=2) { MoveToPoint(point[i]); AddLineToPoint(point[i+1]); StrokePath(); }  
  36. CGContextStrokeLineSegments(context, strokeSegments, sizeof(strokeSegments)/sizeof(strokeSegments[0])); 

效果如下圖:

iPhone繪圖關于QuartZ中繪制Line案例

2.畫虛線

  1. CGContextRef context = UIGraphicsGetCurrentContext();  
  2. CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);  
  3. // Each dash entry is a run-length in the current coordinate system  
  4. // The concept is first you determine how many points in the current system you need to fill.  
  5. // Then you start consuming that many pixels in the dash pattern for each element of the pattern.  
  6. // So for example, if you have a dash pattern of {10, 10}, then you will draw 10 points, then skip 10 points, and repeat.  
  7. // As another example if your dash pattern is {10, 20, 30}, then you draw 10 points, skip 20 points, draw 30 points,  
  8. // skip 10 points, draw 20 points, skip 30 points, and repeat.  
  9. // The dash phase factors into this by stating how many points into the dash pattern to skip.  
  10. // So given a dash pattern of {10, 10} with a phase of 5, you would draw 5 points (since phase plus 5 yields 10 points),  
  11. // then skip 10, draw 10, skip 10, draw 10, etc.  
  12. CGContextSetLineDash(context, dashPhase, dashPattern, dashCount);  
  13. // Draw a horizontal line, vertical line, rectangle and circle for comparison  
  14. CGContextMoveToPoint(context, 10.0, 20.0);  
  15. CGContextAddLineToPoint(context, 310.0, 20.0);  
  16. CGContextMoveToPoint(context, 160.0, 30.0);  
  17. CGContextAddLineToPoint(context, 160.0, 130.0);  
  18. CGContextAddRect(context, CGRectMake(10.0, 30.0, 100.0, 100.0));  
  19. CGContextAddEllipseInRect(context, CGRectMake(210.0, 30.0, 100.0, 100.0));  
  20. // And width 2.0 so they are a bit more visible  
  21. CGContextSetLineWidth(context, 2.0);  
  22. CGContextStrokePath(context); 

其中CGFloat lengths[]是一個CGFloat類型的數組,dashCount表示數組元素的個數。下面將給出5種情況下虛線的圖片:

{{10.0, 10.0}, 2}如下圖,先默認dashPhase為0.

iPhone繪圖關于QuartZ中繪制Line案例

dash pattern為{10,10}表示的是先繪制10 points,然后跳過10 points,然后重復,就向上圖。

{{10.0, 20.0, 10.0}, 3}如下圖:

iPhone繪圖關于QuartZ中繪制Line案例

這是一個奇數個的例子,就是先繪制10 points, 接著跳過20 points,再繪制10points,接著跳過10 points,再繪制20points,在跳過10 points,然后接著重復。

{{10.0, 20.0, 30.0}, 3},如下圖

iPhone繪圖關于QuartZ中繪制Line案例

{{10.0, 20.0, 10.0, 30.0}, 4},如下圖

iPhone繪圖關于QuartZ中繪制Line案例

{{10.0, 10.0, 20.0, 30.0, 50.0}, 5},如下圖:

iPhone繪圖關于QuartZ中繪制Line案例

函數CGContextSetLineDash的函數dashPhase參數表示虛線在繪制的時候跳過多少個points。舉一個例子,dash pattern為{10,10},dashPhase為5,則我們繪制5 points,接著跳過10 points,繪制10, 跳過10 ,繪制10 。。。重復。

小結:iPhone繪圖關于QuartZ繪制Line案例的內容介紹完了,希望本文對你有所幫助!如果想深入了解iphone繪圖的更多內容,請參考:

iPhone繪圖關于QuartZ中繪制Polygons案例

iPhone繪圖關于QuartZ中繪制Curves案例

責任編輯:zhaolei 來源: 新浪博客
相關推薦

2011-08-12 11:01:09

iPhone繪圖QuartZ繪制

2011-08-12 11:08:45

iPhone繪圖QuartZ繪制

2011-08-17 14:32:44

iOS開發繪制

2011-08-09 14:54:29

iPhoneNSDateanotherDate

2011-08-18 15:24:40

iPhone國際化

2011-08-10 18:24:22

iPhone 圖形 繪圖

2011-08-19 10:05:30

iPhone開發

2011-08-15 15:44:46

iPhone開發PDF

2011-08-18 16:24:44

iPhone開發圖片

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-07-29 13:27:48

iPhone 開發 Nib

2011-08-17 14:27:17

Core AnimatQuartz2D

2011-08-22 14:21:24

iPhone開發UIView Anim

2011-08-16 15:48:37

iPhone開發抓圖程序

2011-08-15 13:44:07

iPhone開發UITableView

2011-08-22 15:15:49

iPhone開發NSMutableAr排序

2014-04-29 14:27:59

OpenGL ES 2Android繪制紋理

2011-08-08 14:07:49

iPhone開發 字體

2011-08-15 09:58:25

iPhoneXib文件UITableView

2011-08-17 10:16:35

iPhone應用HTTP請求協議
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 在线观看日本高清二区 | 久久久国产精品 | 国产在线中文字幕 | 韩国精品在线观看 | 成人福利电影 | 成人亚洲精品久久久久软件 | 国内自拍偷拍 | 国产精品成人一区二区 | 日本成人在线观看网站 | 欧美一区二区大片 | 欧美午夜一区二区三区免费大片 | 国产成人精品免高潮在线观看 | 中文字幕高清免费日韩视频在线 | 一级毛片大全免费播放 | 欧美一区二区在线播放 | 美女黄视频网站 | 国产精品亚洲欧美日韩一区在线 | 免费黄色a视频 | 久久国产成人 | av网站免费 | 亚洲在线一区 | 国产精品日韩一区 | 国产一在线 | 日韩三级在线观看 | 国产精品99久久久久久动医院 | 国产精品久久久久婷婷二区次 | 亚洲一区二区三区免费 | 久久网站免费视频 | 日韩视频国产 | 久久久久国产精品一区 | 一级特黄色毛片 | 欧美精品久久久 | 亚洲一区电影 | 在线欧美一区二区 | 久久美国| 国内精品久久久久久久影视简单 | 国产在线精品一区二区 | 日韩一区二区三区四区五区 | 精品一区av| 亚洲精品免费视频 | 青青草原综合久久大伊人精品 |