登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

3DGraph

[复制链接]
来自: 李世铿 分类: iOS精品源码 上传时间: 2016-6-15 15:27:30
Tag:charts 3Dgraph 视图

项目介绍:

3DGraph
一个交互性极强的Swift 3D 视图,非常容易创建且拥有很多自定义属性。

Installation
  • Copy BarNode.swift, LabelNode.swift, GraphNode.swift, BarElement.swift and GraphView.swift to your project.



Usage
[Objective-C] 查看源文件 复制代码
Add a UIView to storyboard or xib and assign a subclass of GraphView (you can also create GraphView in code) Allocate the required constraints should be necessary and appropriate measures according to our needs. The next step would be a sight IBOutlet to assign attributes and data. Once these steps, we pass the data we want to show in the graph, it is an array of BarElement ([BarElement])

//Create `BarElement`

let bar1 = BarElement(width: 200, height:150, length: 200, color: UIColor.orangeColor(), cornerRadius: 2.5)
let bar2 = BarElement(width: 200, height: 150, length: 150, color: UIColor.redColor(), cornerRadius: 2.5)
let bar3 = BarElement(width: 200, height: 150, length: 180, color: UIColor.blueColor(), cornerRadius: 2.5)

// Optionally you can add labels to the bar element, it needs to be ann array of AttributedString
var label1 = NSMutableAttributedString(string: "Count 76")
label1.addAttributes([NSFontAttributeName: UIFont.systemFontOfSize(4), NSForegroundColorAttributeName: UIColor.whiteColor()], range: NSMakeRange(0, 5))
label1.addAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(4.5)], range: NSMakeRange(5, label1.length-5))

var label2 = NSMutableAttributedString(string: "Value 663.4k")
label2.addAttributes([NSFontAttributeName: UIFont.systemFontOfSize(4), NSForegroundColorAttributeName: UIColor.whiteColor()], range: NSMakeRange(0, 5))
label2.addAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(4.5)], range: NSMakeRange(5, label2.length-5))

var label3 = NSMutableAttributedString(string: "Avg demand 178.9k")
label3.addAttributes([NSFontAttributeName: UIFont.systemFontOfSize(4), NSForegroundColorAttributeName: UIColor.whiteColor()], range: NSMakeRange(0, 10))
label3.addAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(4.5)], range: NSMakeRange(10, label3.length-10))

var label4 = NSMutableAttributedString(string: "Fill(90.04%) 91.96%")
label4.addAttributes([NSFontAttributeName: UIFont.systemFontOfSize(4), NSForegroundColorAttributeName: UIColor.whiteColor()], range: NSMakeRange(0, 12))
label4.addAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(4.5)], range: NSMakeRange(12, label4.length-12))

bar1.labels = [label1, label2, label3, label4]
bar2.labels = [label1, label2, label3, label4]
bar3.labels = [label1, label2, label3, label4]



To display the bar elements add it to garElements property of graphView:
[Objective-C] 查看源文件 复制代码
class ViewController: UIViewController {

    @IBOutlet weak var graphView: GraphView!


    override func viewDidAppear(animated: Bool) {
        super.viewWillAppear(animated)

        graphView.barElements = [bar1, bar2, bar3]
        graphView.selectedItemHandler = {
            idx in
            println("Item \(idx) pressed")
        }
    }
}






Customize自定义
[Objective-C] 查看源文件 复制代码
graphView.columns = 4         // Columns in single row
graphView.offset = CGPoint(x: 0, y: -60)  // Let you move the graph inside the view
graphView.labelOffset = CGPoint(x: -10, y: 5)  // Let you move the labels inside bar element
graphView.rotAngleX = -60  // Rotation in degrees for animation after user tap the graph around X axis
graphView.rotAngleY = -18  // Rotation in degrees for animation after user tap the graph around Y axis
graphView.rotateAtTapEnabled = true  // Enable rotation of the graph view on touch
graphView.selectedItemHandler: ((Int) -> ())?  // Handler which is triggered after user touch bar element
graphView.horizontalSpace = 2  // horizontal space between bar elements
graphView.verticalSpace = 2  // vertical space between bar elements
graphView.xAxisLabels  // Set the X Axis labels on the top/bottom of the graph. It's array of NSAttributedString
graphView.yAxisLabels  // Set the Y Axis labels on the left/right of the graph. It's array of NSAttributedString
graphView.xLabelsOnTop = true  // Set the position of xAxisLabels (top/bottom)
graphView.yLabelsOnLeft = true  // Set the position of yAxisLabels (left/right)


Preview Image

DEMO直接下载:



相关源码推荐:

我来说两句
*滑动验证:
所有评论(5)
胡英俊.App 2016-6-15 16:03:11
强烈支持楼主ing……
回复
dagouxionglz 2016-6-16 08:59:05
强烈支持楼主ing……
回复
liujinfeng 2016-6-16 09:30:30
很给力,Code4App有你更精彩!
回复
王颖博 2016-6-16 09:57:04
很给力,Code4App有你更精彩!
回复
0123456789ooooo 2016-6-16 14:13:27
正需要啊,感谢楼主无私分享!
回复
Gen_0 2016-6-18 14:10:23
楼主威武啊,Code4App有你更给力!
回复
浣溪沙 2016-6-21 09:55:36
很给力,Code4App有你更精彩!
回复
caihe888 2016-6-23 11:48:00
正需要啊,感谢楼主无私分享!
回复
123123123wrerew 2016-7-2 15:09:01
感谢分享,Code4App有你更精彩:)
回复
提取码:  下载次数:21 状态:已购或VIP 售价:0(原价:10)金钱 下载权限:初级码农 
671 0 21
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表