自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

IOS開(kāi)發(fā)框架:Core Plot開(kāi)源框架使用

移動(dòng)開(kāi)發(fā) iOS
Core Plot已經(jīng)提供了Mac標(biāo)準(zhǔn)安裝器 CorePlotInstaller_0.2.2.zip , 你可以直接用安裝器安裝,可以很方便地把Core Plot直接以SDK的方式安裝到本機(jī)。

IOS開(kāi)發(fā)框架Core Plot開(kāi)源框架使用是本文要介紹的內(nèi)容,主要是來(lái)學(xué)習(xí)IOS開(kāi)發(fā)框架的學(xué)習(xí)。iPhone下的圖形框架并不是很多。其中比較知名的就兩個(gè)s7graphview和Core Plot。巧的是兩個(gè)都是Google的。前者使用簡(jiǎn)單,但功能單一,只能畫(huà)曲線圖。后者是開(kāi)源項(xiàng)目,項(xiàng)目仍在不斷更新中,用起來(lái)可就復(fù)雜多了,而且各個(gè)版本會(huì)有差異,包括屬性、方法,甚至是類名都有改變。

關(guān)于Core Plot使用的中文網(wǎng)上資料,不是缺乏,而是根本沒(méi)有。唯一的一篇介紹得比較詳細(xì)的文章是“Using Core Plot in an iPhone Application”, 原文是英文的:http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application 。但時(shí)間真的是太老了,居然是09年5月發(fā)表的,原文很多地方已經(jīng)不再適用。因此我費(fèi)了好大的勁,才把原文中的代碼跑通了,不敢獨(dú)享,與各位共享之。

一、下載安裝Core Plot框架

原文介紹的是“源代碼”版本。首先下載并安裝Mercurial(很簡(jiǎn)單,在http://www.selenic.com/mercurial/wiki/ 有標(biāo)準(zhǔn)Mac安裝包下載),再使用命令:

  1. hg clone http://core-plot.googlecode.com/hg/ core-plot 

即可把Core Plot項(xiàng)目源代碼下載到指定目錄core-plot下。

截至本文發(fā)表時(shí)止,Core Plot已經(jīng)提供了Mac標(biāo)準(zhǔn)安裝器 CorePlotInstaller_0.2.2.zip   , 你可以直接用安裝器安裝,可以很方便地把Core Plot直接以SDK的方式安裝到本機(jī)。SDK的使用方法見(jiàn)后一篇博文《Core Plot SDK的用法》。

二、如何在項(xiàng)目中使用Core Plot

由于iOS 的限制,Core Plot以靜態(tài)庫(kù)的形式鏈接到iPhone應(yīng)用。在core-plot/framework目錄下存在CorePlot- CocoaTouch.xcodeproj文件,這就是一個(gè)靜態(tài)庫(kù)項(xiàng)目。關(guān)于靜態(tài)庫(kù)的使用,前一篇博文《封裝自己的控件庫(kù):iPhone靜態(tài)庫(kù)的應(yīng)用》已 經(jīng)有介紹,使用方法都是一樣的。

1、新建Windows-base Application項(xiàng)目。

2、使用Add->Existing Files…,把CorePlot-CocoaTouch.xcodeproj添加到新項(xiàng)目中。

3、把libCorePlot-CocoaTouch.a最右邊的“add to target”小框勾上。

4、選擇Target “info->General”,添加對(duì)項(xiàng)目CorePlot-CocoaTouch的依賴(引用)。

5、選擇新項(xiàng)目的“info->Build”,在“Header Search Paths”中添加Core Plot頭文件搜索路徑,如: /Users/kmyhy/core-plot/framework。注意要選中“Recursive”小勾(英文原文中沒(méi)有提這一點(diǎn))。同時(shí),在Other Linker Flags中要增加兩個(gè)選項(xiàng):-ObjC和-all_load(英文原文中遺漏了第2個(gè)選項(xiàng))。

6、新建一個(gè)ViewController,如TestViewController。在本例中,我們勾選了“With Xib”選項(xiàng)。在英文原文中,要求在Interface Build中把xib的View對(duì)象由UIView改為CPLayerHostingView(其實(shí)應(yīng)當(dāng)是CPGraphHostingView)。但在這里,其實(shí)沒(méi)有必要,只需在源代碼中修改就可以了。

7、.h文件:

  1. #import <UIKit/UIKit.h> 
  2. #import "CorePlot-CocoaTouch.h"  
  3. @interface TestViewController : UIViewController <CPPlotDataSource>{  
  4. CPXYGraph * graph ;  
  5. }  
  6. @end 

8、.m文件:

  1. #import "TestViewController.h"  
  2. @implementation TestViewController  
  3. -( NSUInteger )numberOfRecordsForPlot:( CPPlot *)plot {  
  4. return 51 ;  
  5. }  
  6. -( NSNumber *)numberForPlot:( CPPlot *)plot field:( NSUInteger )fieldEnum recordIndex:( NSUInteger )index {  
  7. double val = (index/ 5.0 )- 5 ;  
  8. if (fieldEnum == CPScatterPlotFieldX )  
  9. { return [ NSNumber numberWithDouble :val]; }  
  10. else  
  11. {  
  12. if (plot. identifier == @"X Squared Plot" )  
  13. { return [ NSNumber numberWithDouble :val*val]; }  
  14. else  
  15. { return [ NSNumber numberWithDouble : 1 /val]; }  
  16. }  
  17. }  
  18.  
  19. - ( void )viewDidLoad {  
  20.     //[super viewDidLoad];  
  21. graph = [[ CPXYGraph alloc ] initWithFrame : self . view . bounds ];  
  22.  
  23. // 原來(lái)的 CPLayerHostingView 由 CPGraphHostingView 所代替  
  24. self . view = [[ CPGraphHostingView alloc ] initWithFrame :[ UIScreen mainScreen ]. bounds ];  
  25.  
  26. CPGraphHostingView *hostingView = ( CPGraphHostingView *) self . view ;  
  27. hostingView. hostedGraph = graph ;  
  28. graph . paddingLeft = 20.0 ;  
  29. graph . paddingTop = 20.0 ;  
  30. graph . paddingRight = 20.0 ;  
  31. graph . paddingBottom = 20.0 ;  
  32.  
  33. CPXYPlotSpace *plotSpace = ( CPXYPlotSpace *) graph . defaultPlotSpace ;  
  34. plotSpace. xRange = [ CPPlotRange plotRangeWithLocation : CPDecimalFromFloat (- 6 )  
  35.    length : CPDecimalFromFloat ( 12 )];  
  36. plotSpace. yRange = [ CPPlotRange plotRangeWithLocation : CPDecimalFromFloat (- 5 )  
  37.    length : CPDecimalFromFloat ( 30 )];  
  38. CPLineStyle *lineStyle = [ CPLineStyle lineStyle ];  
  39.  
  40. //CPLineStyle 的 lineColor 和 lineWidth 已經(jīng)變?yōu)橹蛔x屬性  
  41. // lineStyle.lineColor = [CPColor blackColor];  
  42. // lineStyle.lineWidth = 2.0f;  
  43.  
  44. CPXYAxisSet *axisSet = ( CPXYAxisSet *) graph . axisSet ;  
  45.  
  46. //majorIntervalLength 的類型由 NSDecimalNumber 改變?yōu)?nbsp;NSDecimal  
  47. axisSet. xAxis . majorIntervalLength = [[ NSDecimalNumber decimalNumberWithString : @"5" ] decimalValue ];  
  48. axisSet. xAxis . minorTicksPerInterval = 4 ;  
  49. axisSet. xAxis . majorTickLineStyle = lineStyle;  
  50. axisSet. xAxis . minorTickLineStyle = lineStyle;  
  51. axisSet. xAxis . axisLineStyle = lineStyle;  
  52. axisSet. xAxis . minorTickLength = 5.0f ;  
  53. axisSet. xAxis . majorTickLength = 7.0f ;  
  54.  
  55. //axisLableOffset 屬性由 labelOffset 所代替  
  56. axisSet. xAxis . labelOffset = 3.0f ;  
  57. //      axisSet.xAxis.axisLabelOffset = 3.0f;  
  58.  
  59. axisSet. yAxis . majorIntervalLength = [[ NSDecimalNumber decimalNumberWithString : @"5" ] decimalValue ];  
  60. axisSet. yAxis . minorTicksPerInterval = 4 ;  
  61. axisSet. yAxis . majorTickLineStyle = lineStyle;  
  62. axisSet. yAxis . minorTickLineStyle = lineStyle;  
  63. axisSet. yAxis . axisLineStyle = lineStyle;  
  64. axisSet. yAxis . minorTickLength = 5.0f ;  
  65. axisSet. yAxis . majorTickLength = 7.0f ;  
  66.  
  67. //axisLableOffset 屬性由 labelOffset 所代替  
  68. axisSet. yAxis . labelOffset = 3.0f ;  
  69. //      axisSet.yAxis.axisLabelOffset = 3.0f;  
  70.  
  71. //CPPlotSpace 的 bounds 屬性不再有效  
  72. CPScatterPlot *xSquaredPlot = [[[ CPScatterPlot alloc ]  
  73.    initWithFrame : self . view . bounds ] autorelease ];  
  74. //initWithFrame:graph.defaultPlotSpace.bounds] autorelease];  
  75. xSquaredPlot. identifier = @"X Squared Plot" ;  
  76.  
  77. //CPLineStyle 的 lineColor 和 lineWidth 已經(jīng)變?yōu)橹蛔x屬性  
  78. // xSquaredPlot.dataLineStyle.lineWidth = 1.0f;  
  79. // xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor];  
  80. xSquaredPlot. dataSource = self ;  
  81. [ graph addPlot :xSquaredPlot];  
  82.  
  83. CPPlotSymbol *greenCirclePlotSymbol = [ CPPlotSymbol ellipsePlotSymbol ];  
  84. greenCirclePlotSymbol. fill = [ CPFill fillWithColor :[ CPColor greenColor ]];  
  85. greenCirclePlotSymbol. size = CGSizeMake ( 2.0 , 2.0 );  
  86. xSquaredPlot. plotSymbol = greenCirclePlotSymbol;   
  87.  
  88. //CPPlotSpace 的 bounds 屬性不再有效  
  89. CPScatterPlot *xInversePlot = [[[ CPScatterPlot alloc ]  
  90.    initWithFrame : self . view . bounds ] autorelease ];  
  91. //initWithFrame:graph.defaultPlotSpace.bounds] autorelease];  
  92. xInversePlot. identifier = @"X Inverse Plot" ;  
  93. //CPLineStyle 的 lineColor 和 lineWidth 已經(jīng)變?yōu)橹蛔x屬性  
  94. // xInversePlot.dataLineStyle.lineWidth = 1.0f;  
  95. // xInversePlot.dataLineStyle.lineColor = [CPColor blueColor];  
  96. xInversePlot. dataSource = self ;  
  97. [ graph addPlot :xInversePlot];  
  98. }    
  99. - ( void )dealloc {  
  100.     [ super dealloc ];  
  101. }   
  102. @end 

仔細(xì)查看代碼,你會(huì)發(fā)現(xiàn)原文中的代碼被我做了一些修改和調(diào)整。

附一張Core Plot框架的類層次圖,便于理解代碼中各個(gè)對(duì)象的使用:

注意,右邊各個(gè)類的顏色和左邊各個(gè)層次的顏色是對(duì)應(yīng)的,如圖所示:

IOS開(kāi)發(fā)框架:Core Plot開(kāi)源框架使用

小結(jié):IOS開(kāi)發(fā)框架Core Plot開(kāi)源框架使用的內(nèi)容介紹完了,希望通過(guò)本文的學(xué)習(xí)能對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來(lái)源: 論壇
相關(guān)推薦

2011-08-18 11:19:13

IOS開(kāi)發(fā)Core Plot S

2013-07-24 18:22:02

iOS開(kāi)發(fā)學(xué)習(xí)iOS開(kāi)源框架和類

2016-03-18 09:36:13

ios基礎(chǔ)框架

2019-03-01 08:57:47

iOScoobjc協(xié)程

2011-08-19 13:51:12

2019-09-02 14:51:33

2014-04-21 15:53:59

iOS開(kāi)源項(xiàng)目CocoaLumber

2011-06-15 16:11:51

UIKitCocoa TouchiOS

2009-07-03 16:05:06

JSP開(kāi)發(fā)框架

2012-05-21 21:34:51

iOS

2015-06-24 10:17:24

UI流式布局

2009-06-19 10:09:00

J2EE開(kāi)發(fā)框架

2010-08-11 13:17:07

Flex框架

2018-05-03 19:14:23

iOS開(kāi)發(fā)框架API

2011-04-21 10:59:44

SimpleFrameWeb

2010-08-05 14:03:32

Flex框架

2023-11-16 08:34:23

.NETORM框架

2014-07-10 10:02:01

iOSHome Kit框架

2012-10-08 12:59:01

iOS 6.0開(kāi)發(fā)框架功能更新

2024-05-06 08:44:25

FrugalGPT大型語(yǔ)言模型LLM
點(diǎn)贊
收藏

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