ChromaColorPicker/ChromaColorPicker-Demo/ViewController.swift

59 lines
1.9 KiB
Swift
Raw Normal View History

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
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
colorPicker.currentAngle = Float.pi
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
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
}
}