【发布时间】:2015-08-18 21:06:44
【问题描述】:
我正在尝试使用用户可滚动的 CGRect 绘制折线图。我已将其容器视图设置为可滚动(我想要水平滚动,以便线条可以延伸到屏幕之外),但它似乎没有任何效果。这是我实际视图控制器中的代码:
@IBOutlet weak var containerView: UIScrollView!
@IBOutlet weak var graphView: GraphView!
override func viewDidLoad() {
super.viewDidLoad()
logWeightButton.enabled = false
logWeightField.delegate = self
logWeightField.keyboardType = .NumberPad
self.view.addSubview(containerView)
containerView.addSubview(graphView)
containerView.contentSize = graphView.rectDisplay.size
pageLoad()
}
这是声明 CGRect(在 UIView 类中)的代码
override func drawRect(rect: CGRect) {
if dataPoints.count == 0 {
return
} else {
self.drawLine(dataPoints, rect: rect, xCoordinates: nil, color: UIColor.blackColor())
if xCoordinates.count != 0 {
self.drawLine(actualPoints, rect: rect, xCoordinates: xCoordinates, color: UIColor.redColor())
}
rectDisplay = rect
}
}
【问题讨论】:
标签: ios swift uiscrollview drawrect