Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // CirclePieViewExample
  4. //
  5. // Created by Mark Jackson on 10/8/15.
  6. // Copyright © 2015 Mark Jackson. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. extension Double {
  12. func format(f: String) -> String {
  13. return NSString(format: "%\(f)f", self) as String
  14. }
  15. }
  16.  
  17. class ViewController: UIViewController {
  18.  
  19. @IBOutlet weak var circlePieIndicatorView: CirclePieIndicatorView!
  20.  
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. // Do any additional setup after loading the view, typically from a nib.
  24.  
  25. let values = [0, 150, 300, 0, 150, 300, 0, 150, 300, 0, 150, 300]
  26. var totalValues = 0
  27. for val in values {
  28. totalValues += val
  29. }
  30. let totals = [200, 500, 350, 220, 600, 500, 200, 500, 350, 220, 600, 500]
  31. var totalTotals = 0
  32. for total in totals {
  33. totalTotals += total
  34. }
  35. let percent = (Double(totalValues) / Double(totalTotals)) * 100
  36. circlePieIndicatorView.percentageLabel.text = percent.format(".0") + "%"
  37. circlePieIndicatorView.circlePieView.setSegmentValues(
  38. values,
  39. totals: totals,
  40. colors: [UIColor.greenColor(), UIColor.yellowColor(), UIColor.redColor(), UIColor.greenColor(), UIColor.yellowColor(), UIColor.redColor(), UIColor.greenColor(), UIColor.yellowColor(), UIColor.redColor(), UIColor.greenColor(), UIColor.yellowColor(), UIColor.redColor()])
  41.  
  42. }
  43.  
  44. override func didReceiveMemoryWarning() {
  45. super.didReceiveMemoryWarning()
  46. // Dispose of any resources that can be recreated.
  47. }
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement