I have a the following code which is cocoa touch class, which draws a simple pie chart, and with the value CGFloat I can adjust the image to show the correct amount of Pie.
how can i pass a value for example from a slider in the main view controler.swift to it, instead of having it fixed?
public class PieChart : NSObject {
public class func drawCanvas1(ratio ratio: CGFloat = 0.75) {
//// Variable Declarations
let expression: CGFloat = 90 + ratio * 360
let ovalPath = UIBezierPath(ovalInRect: CGRect(x: 0, y: -0, width: 112, height: 112))
UIColor.blackColor().setFill()
ovalPath.fill()
let oval2Rect = CGRect(x: 4, y: 4, width: 104, height: 104)
let oval2Path = UIBezierPath()
oval2Path.addArcWithCenter(CGPoint(x: oval2Rect.midX, y: oval2Rect.midY), radius: oval2Rect.width / 2, startAngle: -expression * CGFloat(M_PI)/180, endAngle: -90 * CGFloat(M_PI)/180, clockwise: true)
oval2Path.addLineToPoint(CGPoint(x: oval2Rect.midX, y: oval2Rect.midY))
oval2Path.closePath()
UIColor.redColor().setFill()
oval2Path.fill()
}
}
and this is my ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var sliderValue: UISlider!
@IBAction func sliderMoved(sender: UISlider) {
let mySliderValue = sliderValue.value
// this is where I'm stuck ->
drawCanvas1 = Float(mySliderValue)
}
EDIT : Added code from where Piechart is Initialised
import UIKit
@IBDesignable
class PCView: UIView {
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
*/
override func drawRect(rect: CGRect) {
PieChart.drawCanvas1()
}
}
Aucun commentaire:
Enregistrer un commentaire