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

iPhone繪圖關(guān)于QuartZ中繪制Line案例

移動(dòng)開(kāi)發(fā) iOS
iPhone繪圖關(guān)于QuartZ中繪制Line案例是本文要介紹的內(nèi)容,主要介紹了如何在QuartZ中繪制Line的內(nèi)容,來(lái)看詳細(xì)內(nèi)容。

iPhone繪圖關(guān)于QuartZ繪制Line案例是本文要介紹的內(nèi)容,主要介紹了如何在QuartZ繪制Line的內(nèi)容,來(lái)看詳細(xì)內(nèi)容。下面的代碼和例子都是從官方的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繪圖關(guān)于QuartZ中繪制Line案例

2.畫(huà)虛線

  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[]是一個(gè)CGFloat類型的數(shù)組,dashCount表示數(shù)組元素的個(gè)數(shù)。下面將給出5種情況下虛線的圖片:

{{10.0, 10.0}, 2}如下圖,先默認(rèn)dashPhase為0.

iPhone繪圖關(guān)于QuartZ中繪制Line案例

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

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

iPhone繪圖關(guān)于QuartZ中繪制Line案例

這是一個(gè)奇數(shù)個(gè)的例子,就是先繪制10 points, 接著跳過(guò)20 points,再繪制10points,接著跳過(guò)10 points,再繪制20points,在跳過(guò)10 points,然后接著重復(fù)。

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

iPhone繪圖關(guān)于QuartZ中繪制Line案例

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

iPhone繪圖關(guān)于QuartZ中繪制Line案例

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

iPhone繪圖關(guān)于QuartZ中繪制Line案例

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

小結(jié):iPhone繪圖關(guān)于QuartZ繪制Line案例的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!如果想深入了解iphone繪圖的更多內(nèi)容,請(qǐng)參考:

iPhone繪圖關(guān)于QuartZ中繪制Polygons案例

iPhone繪圖關(guān)于QuartZ中繪制Curves案例

責(zé)任編輯:zhaolei 來(lái)源: 新浪博客
相關(guān)推薦

2011-08-12 11:01:09

iPhone繪圖QuartZ繪制

2011-08-12 11:08:45

iPhone繪圖QuartZ繪制

2011-08-17 14:32:44

iOS開(kāi)發(fā)繪制

2011-08-09 14:54:29

iPhoneNSDateanotherDate

2011-08-18 15:24:40

iPhone國(guó)際化

2011-08-10 18:24:22

iPhone 圖形 繪圖

2011-08-19 10:05:30

iPhone開(kāi)發(fā)

2011-08-15 15:44:46

iPhone開(kāi)發(fā)PDF

2011-08-18 16:24:44

iPhone開(kāi)發(fā)圖片

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-07-29 13:27:48

iPhone 開(kāi)發(fā) Nib

2011-08-17 14:27:17

Core AnimatQuartz2D

2011-08-16 15:48:37

iPhone開(kāi)發(fā)抓圖程序

2011-08-22 14:21:24

iPhone開(kāi)發(fā)UIView Anim

2011-08-15 13:44:07

iPhone開(kāi)發(fā)UITableView

2011-08-22 15:15:49

iPhone開(kāi)發(fā)NSMutableAr排序

2014-04-29 14:27:59

OpenGL ES 2Android繪制紋理

2011-08-08 14:07:49

iPhone開(kāi)發(fā) 字體

2011-08-15 09:58:25

iPhoneXib文件UITableView

2011-08-17 10:16:35

iPhone應(yīng)用HTTP請(qǐng)求協(xié)議
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 久久久久久av| 亚洲三区在线 | 欧美日韩亚洲在线 | 成人午夜 | 国产精品久久久久一区二区三区 | 国产成人精品亚洲日本在线观看 | 国产xxx在线观看 | 国产区视频在线观看 | 国产精品三级久久久久久电影 | a级免费黄色片 | 亚洲成人免费 | 久久精品一区二区三区四区 | 自拍偷拍亚洲一区 | 精品国产一区二区久久 | 日韩精品在线一区 | 播放一级黄色片 | 日韩一区二区久久 | 精品视频一区二区三区 | 亚洲欧美日韩精品久久亚洲区 | 亚洲久久一区 | 欧美精品一区在线观看 | 超碰男人天堂 | 日韩免费1区二区电影 | 欧美日韩国产传媒 | 久久久久一区 | 成人av免费在线观看 | 国产亚洲区 | 亚洲五码久久 | 免费精品| 欧美精品一二三区 | 久久久无码精品亚洲日韩按摩 | 国产一区久久精品 | 欧美日韩精品 | 久久久美女 | 小草久久久久久久久爱六 | 日本不卡视频 | 免费电影av| 亚洲精品视频免费 | 视频一区二区中文字幕 | 亚洲午夜精品视频 | avtt国产 |