mirror of
https://github.com/joncardasis/ChromaColorPicker.git
synced 2024-11-29 11:15:55 +03:00
89 lines
2.9 KiB
Swift
89 lines
2.9 KiB
Swift
//
|
|
// ViewController.swift
|
|
// ChromaColorPicker-Demo
|
|
//
|
|
// Created by Cardasis, Jonathan (J.) on 8/11/16.
|
|
// Copyright © 2016 Jonathan Cardasis. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import ChromaColorPicker
|
|
|
|
class ViewController: UIViewController {
|
|
@IBOutlet weak var colorDisplayView: UIView!
|
|
|
|
let colorPicker = ChromaColorPicker2()
|
|
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
|
|
colorPicker.translatesAutoresizingMaskIntoConstraints = false
|
|
view.addSubview(colorPicker)
|
|
|
|
NSLayoutConstraint.activate([
|
|
colorPicker.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
|
colorPicker.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
|
colorPicker.widthAnchor.constraint(equalToConstant: 400),
|
|
colorPicker.heightAnchor.constraint(equalToConstant: 400)
|
|
])
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
class ViewController: UIViewController {
|
|
|
|
@IBOutlet weak var colorDisplayView: UIView!
|
|
var colorPicker: ChromaColorPicker!
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
/* Calculate relative size and origin in bounds */
|
|
let pickerSize = CGSize(width: view.bounds.width*0.8, height: view.bounds.width*0.8)
|
|
let pickerOrigin = CGPoint(x: view.bounds.midX - pickerSize.width/2, y: view.bounds.midY - pickerSize.height/2)
|
|
|
|
/* Create Color Picker */
|
|
colorPicker = ChromaColorPicker(frame: CGRect(origin: pickerOrigin, size: pickerSize))
|
|
colorPicker.delegate = self
|
|
|
|
/* Customize the view (optional) */
|
|
colorPicker.padding = 10
|
|
colorPicker.stroke = 3 //stroke of the rainbow circle
|
|
colorPicker.currentAngle = Float.pi
|
|
|
|
/* Customize for grayscale (optional) */
|
|
colorPicker.supportsShadesOfGray = true // false by default
|
|
//colorPicker.colorToggleButton.grayColorGradientLayer.colors = [UIColor.lightGray.cgColor, UIColor.gray.cgColor] // You can also override gradient colors
|
|
|
|
|
|
colorPicker.hexLabel.textColor = UIColor.white
|
|
|
|
/* Don't want an element like the shade slider? Just hide it: */
|
|
//colorPicker.shadeSlider.hidden = true
|
|
|
|
self.view.addSubview(colorPicker)
|
|
}
|
|
}
|
|
|
|
extension ViewController: ChromaColorPickerDelegate {
|
|
func colorPickerDidChooseColor(_ colorPicker: ChromaColorPicker, color: UIColor) {
|
|
//Set color for the display view
|
|
colorDisplayView.backgroundColor = color
|
|
|
|
//Perform zesty animation
|
|
UIView.animate(withDuration: 0.2,
|
|
animations: {
|
|
self.colorDisplayView.transform = CGAffineTransform(scaleX: 1.05, y: 1.05)
|
|
}, completion: { (done) in
|
|
UIView.animate(withDuration: 0.2, animations: {
|
|
self.colorDisplayView.transform = CGAffineTransform.identity
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
*/
|