1. 本节课将为您演示,如何创建一个饼型图表,并将图表导出为一张图片。首先在左侧的项目导航区,打开视图控制器的代码文件。




5. 然后往数组中,依次添加四条数据,分别表示环型图表各区域的比例。


7. 由于饼型图表分为四部分,这里依次设置这四个部分的填充颜色。




11. 接着在饼型图表的中心位置,添加一个文字标签,并设置文字的内容。


13. 初始化一个字符串,表示图表导出成图片之后的存储位置。

14. 调用图表的存储方法,将图表导出为图片,并设置图片的格式和压缩程度,图片将被保存到沙箱中的指定的文档目录。同时在控制台输出图片的路径信息。

15. 将配置好的图表,添加到根视图中,然后点击左上角的[编译并运行]按钮,启动模拟器预览项目。

16. 在弹出的模拟器中,显示了一张具有不同颜色的饼形图表,并且拥有标题和描述信息。现在关闭模拟器,查看图表导出后的图片文件。
17. 在左侧的圆点处按下手指,并向右侧拖动,以选择图片所在的路径。



20. 依次点击[前往 > 前往文件夹]命令,打开文件夹跳转窗口。


22. 在弹出的前往文件夹窗口中,使用键盘上的快捷键,粘贴刚刚复制的内容。




本文整理自:《app开发中的神兵利器》,真正的[手把手]教学模式,用最快的速度上手iOS开发,苹果商店App Store免费下载:https://itunes.apple.com/cn/app/id1209739676,或扫描本页底部的二维码。课程配套素材下载地址:资料下载

网友评论