SMDiagramViewSwift 1.0.1

SMDiagramViewSwift 1.0.1

pawlo2102 维护。



  • 作者
  • pawlo2102

SMDiagramViewSwift

这是一个为iOS应用程序设计的可爱且非常灵活的库,可以在一个圆形图中显示不同的数据视图。这个示例的可转换性让应用程序交互性强,色彩丰富,有令人惊叹的效果。

CocoaControls

图片

需求

  • Xcode 9
  • iOS 9.x+
  • Swift 4

请务必仔细阅读所有说明。

使用 CocoaPods 安装

use_frameworks! 

pod 'SMDiagramViewSwift', '~> 1.0'

用法

在您的 .storyboard 或 .xib 文件中添加一个 UIView 实例,设置 SMDiagramView 类,连接 IBOutlet 并添加 DataSource

import SMDiagramViewSwift

class ViewController: UIViewController, SMDiagramViewDataSource {
    
    let dataSource = [1, 2, 3, 4, 5]
    
    @IBOutlet weak var diagramView: SMDiagramView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        diagramView.dataSource = self
    }
}

如果需要,设置 SMDiagramView

    override func viewDidLoad() {
        super.viewDidLoad()
        
        diagramView.dataSource = self
        diagramView.minProportion = 0.1
        diagramView.diagramViewMode = .arc // or .segment
        diagramView.diagramOffset = .zero
        diagramView.radiusOfSegments = 80.0
        diagramView.radiusOfViews = 130.0
        diagramView.arcWidth = 6.0 //Ignoring for SMDiagramViewMode.segment
        diagramView.startAngle = -.pi/2
        diagramView.endAngle = 2.0 * .pi - .pi/2.0
        diagramView.colorOfSegments = .black
        diagramView.viewsOffset = .zero
        diagramView.separatorWidh = 1.0
        public var separatorColor = .white
}

DataSource 函数

    //Required
    func numberOfSegmentsIn(diagramView: SMDiagramView) -> Int {
        return dataSource.count
    }
    
    //Optional
    func diagramView(_ diagramView: SMDiagramView, proportionForSegmentAtIndex index: NSInteger) -> CGFloat {
        return CGFloat(1/dataSource.count)
    }
    func diagramView(_ diagramView: SMDiagramView, colorForSegmentAtIndex index: NSInteger, angle: CGFloat) -> UIColor? {
        return .black
    }
    func diagramView(_ diagramView: SMDiagramView, viewForSegmentAtIndex index: NSInteger, colorOfSegment color:UIColor?, angle: CGFloat) -> UIView? {
        return UIView()
    }
    func diagramView(_ diagramView: SMDiagramView, offsetForView view: UIView?, atIndex index: NSInteger, angle: CGFloat) -> CGPoint {
        return .zero
    }
    func diagramView(_ diagramView: SMDiagramView, radiusForView view: UIView?, atIndex index: NSInteger, radiusOfSegment radius: CGFloat, angle: CGFloat) -> CGFloat {
        return 130.0
    }
    func diagramView(_ diagramView: SMDiagramView, radiusForSegmentAtIndex index: NSInteger, proportion: CGFloat, angle: CGFloat) -> CGFloat {
        return 80.0
    }
    func diagramView(_ diagramView: SMDiagramView, lineWidthForSegmentAtIndex index: NSInteger, angle: CGFloat) -> CGFloat {
        //not called for SMDiagramViewModeSegment
        return 6.0
    }

兼容性

  • IOS 9-11

变更日志

版本:1.0

  • 初始构建

贡献者

  • 欢迎贡献者和星星。

许可

Copyright 2017 VRG Soft

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

[https://apache.ac.cn/licenses/LICENSE-2.0](https://apache.ac.cn/licenses/LICENSE-2.0)

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.