我正在尝试以编程方式在viewDidLoad方法中添加UILabel,下面的代码在按下按钮但不在onViewDidLoad上调用时有效。我想在第一次将视图加载到屏幕上时显示标签。
override func viewDidLoad()
{
super.viewDidLoad()
BarGraphView.isRandomColor = true
let labelsArray:[String] = ["A","B","C","D","E","F","G"]
var graphPoints: [CGFloat] = [4,8,6,8,5,6,8]
bar.plotGraph(labelsArray, data: graphPoints)
lineGraph.plotGraph(labelsArray, data: graphPoints,view: view)
for i in 0..<lineGraph.graphXAxisPoints.count {
print("graph x point ==>"+String(lineGraph.graphXAxisPoints.count))
let labelWidth: CGFloat = 20.0
var tempLabel = UILabel()
print("i value ==>"+String(i))
var point: CGPoint = CGPoint(x: lineGraph.graphXAxisPoints[i] - labelWidth/2, y: CGFloat( lineGraph.bounds.height - 20) )
tempLabel.frame = CGRect(origin: point, size: CGSize(width: labelWidth, height: 10))
tempLabel.textAlignment = NSTextAlignment.Center
tempLabel.textColor = UIColor.blackColor()
tempLabel.tag = i+1
tempLabel.text = labelsArray[i]**
lineGraph.addSubview(tempLabel)
let view1 = lineGraph.viewWithTag(i+1)
lineGraph.addSubview(view1!)
}
print("refreshing")
self.view.setNeedsDisplay()
lineGraph.setNeedsLayout()
}
答案 0 :(得分:0)
您应该将此代码放在low[x] = disc[v]
中,然后才能运行。