2016-08-11 21:02:26 +03:00
|
|
|
//
|
|
|
|
// ViewController.swift
|
2016-08-15 19:55:11 +03:00
|
|
|
// ChromaColorPicker-Demo
|
2016-08-11 21:02:26 +03:00
|
|
|
//
|
|
|
|
// Created by Cardasis, Jonathan (J.) on 8/11/16.
|
|
|
|
// Copyright © 2016 Jonathan Cardasis. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2017-07-24 23:14:05 +03:00
|
|
|
import ChromaColorPicker
|
2016-08-11 21:02:26 +03:00
|
|
|
|
|
|
|
class ViewController: UIViewController {
|
2016-08-11 22:51:22 +03:00
|
|
|
|
|
|
|
@IBOutlet weak var colorDisplayView: UIView!
|
2016-08-15 19:55:11 +03:00
|
|
|
var colorPicker: ChromaColorPicker!
|
2016-08-11 22:51:22 +03:00
|
|
|
|
2016-08-11 21:02:26 +03:00
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
2016-08-11 22:51:22 +03:00
|
|
|
|
|
|
|
//Calculate relative size and origin in bounds
|
|
|
|
let pickerSize = CGSize(width: view.bounds.width*0.8, height: view.bounds.width*0.8)
|
2016-12-30 23:29:30 +03:00
|
|
|
let pickerOrigin = CGPoint(x: view.bounds.midX - pickerSize.width/2, y: view.bounds.midY - pickerSize.height/2)
|
2016-08-11 22:51:22 +03:00
|
|
|
|
|
|
|
//Create Color Picker
|
2016-08-15 19:55:11 +03:00
|
|
|
colorPicker = ChromaColorPicker(frame: CGRect(origin: pickerOrigin, size: pickerSize))
|
2016-08-11 22:51:22 +03:00
|
|
|
colorPicker.delegate = self
|
|
|
|
|
|
|
|
//Customize the view (optional)
|
|
|
|
colorPicker.padding = 10
|
|
|
|
colorPicker.stroke = 3 //stroke of the rainbow circle
|
2017-05-18 22:49:48 +03:00
|
|
|
colorPicker.currentAngle = Float.pi
|
2016-09-09 22:33:24 +03:00
|
|
|
|
2016-12-30 23:29:30 +03:00
|
|
|
colorPicker.hexLabel.textColor = UIColor.white
|
2016-08-11 22:51:22 +03:00
|
|
|
|
|
|
|
//Don't want an element like the shade slider? Just hide it:
|
|
|
|
//colorPicker.shadeSlider.hidden = true
|
|
|
|
|
2017-01-07 04:17:33 +03:00
|
|
|
self.view.addSubview(colorPicker)
|
|
|
|
}
|
2016-08-11 22:51:22 +03:00
|
|
|
}
|
2016-08-11 21:02:26 +03:00
|
|
|
|
2016-08-15 19:55:11 +03:00
|
|
|
extension ViewController: ChromaColorPickerDelegate{
|
2016-12-30 23:29:30 +03:00
|
|
|
func colorPickerDidChooseColor(_ colorPicker: ChromaColorPicker, color: UIColor) {
|
2016-08-11 22:51:22 +03:00
|
|
|
//Set color for the display view
|
|
|
|
colorDisplayView.backgroundColor = color
|
|
|
|
|
|
|
|
//Perform zesty animation
|
2016-12-30 23:29:30 +03:00
|
|
|
UIView.animate(withDuration: 0.2,
|
2016-08-11 22:51:22 +03:00
|
|
|
animations: {
|
2016-12-30 23:29:30 +03:00
|
|
|
self.colorDisplayView.transform = CGAffineTransform(scaleX: 1.05, y: 1.05)
|
|
|
|
}, completion: { (done) in
|
|
|
|
UIView.animate(withDuration: 0.2, animations: {
|
|
|
|
self.colorDisplayView.transform = CGAffineTransform.identity
|
2016-08-11 22:51:22 +03:00
|
|
|
})
|
2016-12-30 23:29:30 +03:00
|
|
|
})
|
2016-08-11 21:02:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|