一个简单的折线图库
将以下行添加到您的 Podfile
pod "MLLineChart"
$ pod install
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
要使用 CocoaPods 将 MLLineChart 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
pod 'MLLineChart', '~> 2.0.5'
然后,运行以下命令
$ pod install
Carthage 是一个去中心化的依赖管理器,它可以自动化向您的 Cocoa 应用程序添加框架的过程。
您可以使用 Homebrew 使用以下命令安装 Carthage
$ brew update
$ brew install carthage
要使用 Carthage 将 MLLineChart 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它
github "micheltlutz/MLLineChart" ~> 2.0.5
如果您不想使用上述任何依赖管理器,您可以手动将 MLLineChart 集成到您的项目中。
cd
进入您的顶层项目目录,并运行以下命令 “如果” 您的项目尚未初始化为 git 仓库$ git init
$ git submodule add https://github.com/micheltlutz/MLLineChart.git
$ git submodule update --init --recursive
打开新的 MLLineChart
文件夹,并将 MLLineChart.xcodeproj
拖到您的应用程序 Xcode 项目的 Project Navigator 中。
它应该嵌套在您的应用程序蓝色项目图标下方。它在所有其他 Xcode 组之上还是之下并不重要。
在 Project Navigator 中选择 MLLineChart.xcodeproj
,并验证部署目标是否与您的应用程序目标匹配。
接下来,在 Project Navigator 中选择您的应用程序项目(蓝色项目图标),导航到目标配置窗口,然后在侧边栏的 “Targets” 标题下选择应用程序目标。
在该窗口顶部的选项卡栏中,打开 “General” 面板。
点击 “Embedded Binaries” 部分下的 +
按钮。
您将看到两个不同的 MLLineChart.xcodeproj
文件夹,每个文件夹内都有两个不同版本的 MLLineChart.framework
嵌套在 Products
文件夹中。
选择哪个
Products
文件夹并不重要。
选择 MLLineChart.framework
。
就这样!
MLLineChart.framework
被自动添加为目标依赖项、链接框架和嵌入式框架,在一个复制文件构建阶段中,这就是在模拟器和设备上构建所需的一切。
+
按钮。MLLineChart.framework
。import MLLineChart
class ViewController: UIViewController {
private var lineChart: MLLineChart!
private var dataEntries: [MLPointEntry] = []
var widthChart = CGFloat(320)
var heightChart = CGFloat(275)
override func viewDidLoad() {
super.viewDidLoad()
makeData()
setupChart()
}
private func makeData() {
dataEntries.append(MLPointEntry(value: 5, label: "1", color: .gray))
dataEntries.append(MLPointEntry(value: 6, label: "2", color: .green))
dataEntries.append(MLPointEntry(value: 4, label: "3", color: .blue))
}
private func setupChart() {
lineChart = MLLineChart(frame: CGRect(x: 0, y: 0, width: widthChart, height: heightChart))
lineChart.translatesAutoresizingMaskIntoConstraints = false
lineChart.dataEntries = dataEntries
lineChart.lineColor = .gray
lineChart.lineWidth = 2
lineChart.showShadows = true
lineChart.showAxisLine = true
lineChart.gradienLinesColors = [UIColor.gray.cgColor, UIColor.green.cgColor, UIColor.blue.cgColor]
lineChart.configLabelsBottom = MLLabelConfig(color: .white,
backgroundColor: .gray,
rounded: true,
font: UIFont.systemFont(ofSize: 11),
width: 16, height: 16, fontSize: 11)
}
/// Cntinue your code
}
MLLineChart 文档 (- 已记录)
在此项目上使用 MLLineChartDemo Target
欢迎提交 Issue 和 Pull Request!
Michel Anderson Lutz Teixeira @michel_lutz
MLLineChart 基于 MIT 许可证发布。有关详细信息,请参阅 LICENSE。