swift-linechart icon indicating copy to clipboard operation
swift-linechart copied to clipboard

Story Board Implementation

Open mugsinc opened this issue 9 years ago • 3 comments

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

mugsinc avatar Sep 23 '15 11:09 mugsinc

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])

awoodall avatar Sep 26 '15 05:09 awoodall

@mugsinc I was able to use this LineChart View with storyboards using the following workflow:

  1. Add a UIView to your target Storyboard scene.
  2. With the UIView selected, go to the Identity Inspector. Under the top Custom Class section, explicitly set the Class to 'Line Chart'
  3. Add the UIView as an IBOutlet to your associated Controller class. For example ... @IBOutlet weak var lineChart: LineChart!
  4. Because you have a UIView representing the ListView in a storyboard scene, add auto-layout constraints as needed.
  5. In your associated Controller class continue to configure the Line Chart programmatically per the docs

ccabanero avatar Mar 17 '17 09:03 ccabanero

As @ccabanero said it is true, just avoid addsubview() and addcontranints() code in your view controller.

arshadsk5 avatar Apr 03 '17 12:04 arshadsk5