EasyBarChart 0.2.1

EasyBarChart 0.2.1

Yasir Ali 维护。



  • yasirfolio3

EasyBarChart

CI Status Version License Platform EasyBarChart hero EasyBarChart hero EasyBarChart hero EasyBarChart hero

特性

  1. 此库允许您创建多个条形图
  2. 如同示例所见,易用性是重中之重
  3. 支持 iPad 和 iPhone 分辨率,并适用于所有方向
  4. 请遵循示例项目进行正确的实现,特别是方向更改

使用方法

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

使用此代码生成图表

@IBOutlet weak var collectionView: UICollectionView!
var items = [BarDataModel]()
var barDataSource: BarDataSource!

override func viewDidLoad() {
    super.viewDidLoad()

    self.populateTemporaryItems() 
    barDataSource = BarDataSource(items: items, collectionView: collectionView, cellHeightToWidthRatio: 5)
    collectionView.dataSource = barDataSource
    collectionView.reloadData()
}

//Method to fill items Array
func populateTemporaryItems() {
    for n in 0...20{
        let barModel = BarDataModel()
        barModel.showArrow = (n % 2 == 0)
        barModel.barSize = 50
        barModel.backgroundImage = UIImage(named: "paper")!
        barModel.separatorColor = UIColor.red
        barModel.categoryImage = UIImage(named: "png")!
        barModel.topLabelText = "50"
        barModel.topLabelTextColor = UIColor.white
        barModel.topLabelBackgroundColor = UIColor.red
        barModel.bottomLabelText = "Title"

        self.items.append(barModel)
    }
}

在您视图控制器中使用以下方法来处理方向和设备更改

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    barDataSource.recalculateCellSizes()
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    barDataSource.recalculateCellSizes()
}

要求

Swift 4.1
XCode 9.3

安装

EasyBarChart可以通过CocoaPods获取。要安装它,只需将以下行添加到Podfile中

pod 'EasyBarChart'

作者

yasirfolio3, [email protected]

许可协议

EasyBarChart遵循MIT许可协议。更多信息请参阅LICENSE文件。