swift-linechart
swift-linechart copied to clipboard
Story Board Implementation
How can this be implement onto a StoryBoard With a UIView, is there a version of the line chart which has a story board. Please help
You can add a graph to a UIView() by creating an outlet for your view then adding your graph to the subview.
@IBOutlet var LineGraphView: UIView!
lineChart = LineChart()
LineGraphView.addSubview(lineChart)
let horizontalConstraint = lineChart.centerXAnchor.constraintEqualToAnchor(LineGraphView.centerXAnchor)
let vertivalConstraint = lineChart.centerYAnchor.constraintEqualToAnchor(LineGraphView.centerYAnchor)
let widthConstraint = lineChart.widthAnchor.constraintEqualToAnchor(nil, constant: self.view.frame.size.width + 30)
let heightConstraint = lineChart.heightAnchor.constraintEqualToAnchor(nil, constant: 170)
NSLayoutConstraint.activateConstraints([horizontalConstraint, vertivalConstraint, widthConstraint, heightConstraint])
@mugsinc I was able to use this LineChart View with storyboards using the following workflow:
- Add a UIView to your target Storyboard scene.
- With the UIView selected, go to the Identity Inspector. Under the top Custom Class section, explicitly set the Class to 'Line Chart'
- Add the UIView as an IBOutlet to your associated Controller class. For example ... @IBOutlet weak var lineChart: LineChart!
- Because you have a UIView representing the ListView in a storyboard scene, add auto-layout constraints as needed.
- In your associated Controller class continue to configure the Line Chart programmatically per the docs
As @ccabanero said it is true, just avoid addsubview() and addcontranints() code in your view controller.