Swift 核心情节初学者

Core Plot in Swift for Beginner

嗨,我刚开始学习 Swift 并设法使用 CocoaPods 导入 CorePlot,并通过桥接 Header 进行导入。我还设法为我的图表创建了坐标轴:

class ViewController: UIViewController {

@IBOutlet weak var graphView: CPTGraphHostingView!

override func viewDidLoad() {
super.viewDidLoad()

// create graph
var graph = CPTXYGraph(frame: CGRectZero)

graph.paddingLeft = 5
graph.paddingTop = 5
graph.paddingRight = 5
graph.paddingBottom = 5
// Axes
var axes = graph.axisSet as CPTXYAxisSet
var lineStyle = CPTMutableLineStyle()
lineStyle.lineWidth = 2
axes.xAxis.axisLineStyle = lineStyle
axes.yAxis.axisLineStyle = lineStyle

self.graphView.hostedGraph = graph
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

1) 我的问题是,如何标记坐标轴(使用数组)?

2) 还有办法按比例设置标签之间的距离还是自动完成?

我的主要问题是我不知道如何在 Swift 中编写 Objective C 语法。有很多 objc 示例,但我需要 swift.

提前感谢您的耐心等待和帮助!

labelingPolicy 控制刻度间距和标签。使用自定义标签 (CPTAxisLabelingPolicyNone),您可以为每个标签指定一个位置。如果你想要刻度线 and/or 网格线,你需要分别设置这些位置(majorTickLocations and/or minorTickLocations)。

Plot Gallery 示例应用程序中有一个标签政策演示,其中显示了可用的选项。