在lion 中使用xcode4.2.1 和 Core Plot 0.9版本对iphone 手机应用开发 图表

Core Plot 下载地址

http://code.google.com/p/core-plot/downloads/list

一.Core Plot有2种使用方法

  1. 基于项目的使用
  2. 基于静态库的使用

由于我使用的是最新版本的xcode4.2.1。对静态库的使用可能会有问题,所以不采用这种方式,而是采用 基于项目的方式

并且Core Plot在 MAC应用编程和iPhone,iPad应用编程也有所不同。

我们不讨论MAC应用的编程。只讨论iPhone和iPad应用。

官方文档内容如下:原文链接

Using Core Plot Within an Application

Core Plot works on both Mac and iPhone / iPod touch. The framework must be integrated into a project in different ways for each platform.

Mac Application

Core Plot on the Mac is a standard framework. After pulling down the latest source code for the framework, there are only a few steps required to insert it into one of your projects.

First, you will want to make sure that Core Plot is compiled alongside your application, so drag the CorePlot.xcodeproj bundle into your application's Xcode project (without copying the file). Then go to the Targets tab in Xcode, select your application's target, and bring up the inspector. Go to the General settings page and add the CorePlot framework from CorePlot.xcodeproj as a direct dependency.

The framework will need to be copied into your app bundle, so add a new build phase to your application's target by Ctrl-clicking on it and selecting Add | New Build Phase | New Copy Files Build Phase. Within the inspector that appears, change the destination to Frameworks. Drag CorePlot.framework from within the CorePlot.xcodeproj group into this build phase.

To link Core Plot to your target application, drag CorePlot.framework from inside the CorePlot.xcodeproj group into the Link Binary with Libraries build phase in your app's target.

Because Core Plot is based on Core Animation, you need to add the QuartzCore framework to your application project as well.

To import all of the Core Plot classes and data types, add the following to the appropriate source files within your project:

#import <CorePlot/CorePlot.h>

iPhone, iPod Touch, and/or iPad Application

Dependent Project Install

Because frameworks cannot be used in Cocoa Touch applications in the same way as on the Mac, the means of including Core Plot within an iPhone application are slightly different.

First, drag the CorePlot-CocoaTouch.xcodeproj file into your iPhone application's Xcode project. Show the project navigator in the left-hand list and click on your project.

Select your application target from under the "Targets" source list that appears. Click on the "Build Phases" tab and expand the "Target Dependencies" group. Click on the plus button, select the CorePlot-CocoaTouch library, and click Add. This should ensure that the Core Plot library will be built with your application.

Core Plot is built as a static library for iPhone, so you'll need to drag the libCorePlot-CocoaTouch.a static library from under the CorePlot-CocoaTouch.xcodeproj group to the "Link Binaries With Libraries" group within the application target's "Build Phases" group you were just in.

You'll also need to point to the right header location. Under your Build settings, set the Header Search Paths to the relative path from your application to the framework/ subdirectory within the Core Plot source tree. Make sure to make this header search path recursive. You need to add -ObjC to Other Linker Flags as well (as of Xcode 4.2, -all_load does not seem to be needed, but it may be required for older Xcode versions).

Core Plot is based on Core Animation, so if you haven't already, add the QuartzCore framework to your application project.

Finally, you should be able to import all of the Core Plot classes and data types by inserting the following line in the appropriate source files within your project:

#import "CorePlot-CocoaTouch.h"

You can see some examples of plot types and features we might want to have in Core Plot atPlotExamples.

大致翻译以下有关iPhone使用基于项目方式的方法和过程:

Because frameworks cannot be used in Cocoa Touch applications in the same way as on the Mac, the means of including Core Plot within an iPhone application are slightly different.

因为这个框架在Cocoa Touch和Mac应用上有所不同,所以使用方法也略有区别。

First, drag the CorePlot-CocoaTouch.xcodeproj file into your iPhone application's Xcode project. Show the project navigator in the left-hand list and click on your project.

首先,拖拉 CorePlot-CocoaTouch.xcodeproj文件到项目中。位置是在点击项目后,显示在左侧的navigator视图。

Select your application target from under the "Targets" source list that appears. Click on the "Build Phases" tab and expand the "Target Dependencies" group. Click on the plus button, select the CorePlot-CocoaTouch library, and click Add. This should ensure that the Core Plot library will be built with your application.

点击项目名字。在右侧主窗口,显示的区域选择 "Targets",然后点击 "Build Phases" 的tab。在tab视图下展开 "Target Dependencies"。然后点击“+”的按钮。选择“CorePlot-CocoaTouch library”。这个动作是为了让你自己应用能能够构建CorePlot-CocoaTouch library

Core Plot is built as a static library for iPhone, so you'll need to drag the libCorePlot-CocoaTouch.a static library from under the CorePlot-CocoaTouch.xcodeproj group to the "Link Binaries With Libraries" group within the application target's "Build Phases" group you were just in.

由于Core Plot在iphone上使用静态库的方式,所以,我们还需要把 libCorePlot-CocoaTouch.a  这个静态库,从 CorePlot-CocoaTouch.xcodeproj中拖拉到 "Link Binaries With Libraries"group,这个“"Link Binaries With Libraries"” 位于  项目的 target 中 "Build Phases"下。

You'll also need to point to the right header location. Under your Build settings, set the Header Search Paths to the relative path from your application to the framework/ subdirectory within the Core Plot source tree. Make sure to make this header search path recursive. You need to add -ObjC to Other Linker Flags as well (as of Xcode 4.2, -all_load does not seem to be needed, but it may be required for older Xcode versions).

我们还需要加入头文件的指向。在PROJECT 下的“Build settings”,设置“ Header Search Paths” 加入一个从你项目到Core Plot的源码中的framework的目录的相当路径(我的项目设置的是“../../../CorePlot_0.9/Source/framework”这个字符串)。同时要选中 recursive这个选项。同时还要在“Other Linker Flags”中加入 "-ObjC".(在Xcode4.2中不要加入-all_load,如果是低版本的xcode,则需要加入).

Core Plot is based on Core Animation, so if you haven't already, add the QuartzCore framework to your application project.

Core Plot基于核心动画,所以还需要确定在你的项目中加入了“ QuartzCore framework”.

Finally, you should be able to import all of the Core Plot classes and data types by inserting the following line in the appropriate source files within your project:

最后,在自己的项目源码中加入

#import "CorePlot-CocoaTouch.h"
注意,不是加入
#import <CorePlot/CorePlot.h>
这个是用于mac应用开发的。


配置的界面。本文所说的内容并未在截图上完全显示


在我自己使用的这个流程过程中遇到的一些问题以及解决办法

  1. 项目编译出错。提示在Core Plot的头文件中定义的一些变量出现 “assigned” 和“weak”关键词冲突的错误。解决办法:修改Core Plot的源码。去掉--weak的修饰。直到编译通过。(有什么后遗症还不知道。)
  2. 变异网上一些代码,编译会报告类没有发现的错误。解决办法:所有的Core Plot的类 都是通过CPT开头的,而网上的代码用的是CP开头的,都是用于MAC开发的。因此只要把CP开头的类改成CPT开头的,就可以了
  3. 类似这种代码:y. titleLocation =150.0f ;编译报错,错误是不能吧 float类型转换成NSDecimal。解决办法:其中的一些Core Plot类中的属性,使用的是NSDecimal。所以类似这样的赋值,需要修改成这样的代码  y. titleLocation = CPTDecimalFromFloat ( 150.0f );  barPlot. baseValue = CPTDecimalFromString ( @"1" ); 通过Core Plot的提供的方法来把对象进行转换。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值