Charts是一款强大的iOS图形库,但是是swift的, OC项目导入时可能会遇到一些坑,本文基于xcode8.1和swift3.0做最新的集成
一. github下载Charts
https://github.com/danielgindi/Charts
二. 复制Charts-master整个文件到demo工程中

Snip20161216_2.png
三. 将Charts文件夹中的Charts.xcodeproj工程文件导入到ChartsDemo工程中,注意导入的是Charts.xcodeproj工程,而不是Charts文件夹,如下图:

Snip20161216_3.png
四. 导入framework
General --> Embedded Binaries --> + ,选择这个

Snip20161216_4.png
五. 新建OC和swift的桥接文件
新建swift文件,名字可以随意

Snip20161216_5.png
选最后一个

Snip20161216_7.png
会看到xcode中生成这两个文件

Snip20161216_8.png
六. 导入Charts文件
在demo2-Bridging-Header.h中

Snip20161216_9.png
七. 编译,如果有问题的检查以下配置是否正确
设置如下,Product Module Name为工程名
八. 在ViewController.m里测试具体配置可以看下这里:传送门
导入demo2-Bridging-Header.h, viewDidLoad中写以下代码
BarChartView *chatView = [[BarChartView alloc] initWithFrame:CGRectMake(5,5, [UIScreenmainScreen].bounds.size.width -10, [UIScreenmainScreen].bounds.size.height -10)]; [self.view addSubview:chatView];
如果屏幕中出现以下文字,那就是集成好了

Simulator Screen Shot 2016年12月16日 下午10.24.56.png
另外, 使用cocoapods集成也是可以的, 但是注意xcode在集成swift库时,需要强制加上use_frameworks!, 否则会报错, podfile的书写形式为

Snip20161216_10.png
de'mo2换成你项目的名字,其他步骤参照上面吧
网友评论