公司的项目有大量的图标,曲线图,饼图,离散图,柱状图等等。。。选用Charts,毕竟有GitHub上有一万多颗星。Charts是swift写的,而我的项目是OC+swift混编的,如何混编->请移步(稍后更新链接)
先移步GitHub欣赏下大神的代码https://github.com/danielgindi/Charts
顺带看看示例图


下面开始框架的集成,我选用的是直接野蛮拖入法(公司网速不给力,pod半天没反应。。。)
1.下载demo源码
Charts
2.新建一个OC工程项目,工程目录如下:

3.将下载下来的demo中的Charts-master文件夹拖进工程中。!!!注意是在Finder中拖进去,如图:

4.拖进去后,如图:

5.回到项目中,将刚刚拖进来的Charts-master文件夹中的Charts.xcodeproj 拖进xcode中如下:


6.接下来需要配置一些东西




很重要的一点,亲自爬过的坑,少导入一个地方,然后结果是模拟器能跑,真机起来就挂!!!
7.新建一个swift文件,名字随意,这里取名为 ChartsConnect.swift


8,在桥接文件中引入Charts

9,在controller中引入 两个文件,可能没有提示,需要自己手写。我引入时是有提示的
ChartsDemo-Bridging-Header.h 用于桥接OC和swift的
ChartsDemo-Swift.h是系统生成的,为了让OC可以用swift,生成的类似于OC中的.h文件

10,开撸.先clean一下,编译,没有错误,没有警告。
然后创建控制器代码
LineChartView *charView = [[LineChartView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:charView];
运行如图:

11.至此,手动导入Charts框架完成。后续还有。。。之所以不用pod,实在是公司网太慢。。。
传送门
网友评论