1. 程式人生 > >在iOS專案中使用CorePlot框架

在iOS專案中使用CorePlot框架

Core Plot是OS X和IOS下的一個開源圖形庫,它提供資料的視覺化處理,就是畫曲線圖、柱狀圖和餅圖等等。如何在專案中使用Core Plot的靜態庫呢?以下是幾個步驟:

首先先去Google Code下載Core Plot圖形庫,網址 http://code.google.com/p/core-plot/ 。目前該網址提供了CorePlot_1.0.zip下載,下載後解壓。

然後開啟壓縮包中的ReadMes檔案中的“README for Static Library Install”檔案,該檔案內容如下:

Install Binaries for iOS

1. Copy the CorePlotHeaders

to your Xcode project

2. Copy libCorePlotCocoaTouch.a to your Xcode project

3. Add to Other Linker Flags in your target build settings:

-ObjC -all_load

4. Add the QuartzCore framework to the project.

5. Add a CPTGraph to your application. See the example apps in Source Code to see how, or read the documentation.


其實如何使用CorePlot的靜態庫該文件說明的很清楚了,以下結合示意圖說明如何操作。

1.找到剛才壓縮包中的"Binaries-->iOS"資料夾,把整個“CorePlotHeaders”資料夾拷貝到專案中,拷貝的時候記得選上“Copy items into destination group's folder(if need)”選項。

2.把上述資料夾中的"libCorePlotCocoaTouch.a"拷貝到專案中,也選上“Copy items into destination group's folder(if need)”選項。

3.專案目標的編譯設定的“Other Linker Flags”選擇項中加入  “-ObjC -all_load”

完成以上幾個步驟後大致如下圖所示,注意畫紅線的地方:


4.把“QuartzCore”框架加入專案中,操作如下:


到此已經可以工作了,第5點實際上是針對程式設計的,告訴你要把圖形畫在“CPTGraph”上。具體的程式碼可以參考CorePlot壓縮包自帶examples, 其中在ios下有個例子比較有用:“CorePlotGallery” 。