-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
673 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...tableApp/Playground/UserInterfaces/Gradients/GradientCustomStartPointViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// GradientCustomStartPointViewController.swift | ||
// IBAnimatable | ||
// | ||
// Created by Tom Baranes on 22/12/2016. | ||
// Copyright © 2016 IBAnimatable. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import IBAnimatable | ||
|
||
final class GradientCustomStartPointViewController: UIViewController { | ||
|
||
@IBOutlet fileprivate weak var gView: AnimatableView! | ||
|
||
var useRadialGradient = false | ||
let gradientValues = ParamType(fromEnum: GradientType.self) | ||
let coordPointValues = ParamType.number(min: 0, max: 1, interval: 0.1, ascending: true, unit: "") | ||
lazy var componentValues: [ParamType] = [self.gradientValues, | ||
self.coordPointValues, | ||
self.coordPointValues, | ||
self.coordPointValues, | ||
self.coordPointValues] | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
gView.gradientMode = useRadialGradient ? .radial : .linear | ||
gView.predefinedGradient = GradientType(rawValue: gradientValues.value(at: 0)) | ||
} | ||
} | ||
|
||
extension GradientCustomStartPointViewController: UIPickerViewDelegate, UIPickerViewDataSource { | ||
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { | ||
return componentValues[component].count() | ||
} | ||
|
||
func numberOfComponents(in pickerView: UIPickerView) -> Int { | ||
return componentValues.count | ||
} | ||
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { | ||
let label = UILabel() | ||
label.textColor = .white | ||
label.textAlignment = .center | ||
label.minimumScaleFactor = 0.5 | ||
label.text = componentValues[component].title(at: row) | ||
return label | ||
} | ||
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? { | ||
return componentValues[component].title(at: row).colorize(.white) | ||
} | ||
|
||
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { | ||
let startX = pickerView.selectedRow(inComponent: 1) | ||
let startY = pickerView.selectedRow(inComponent: 2) | ||
let endX = pickerView.selectedRow(inComponent: 3) | ||
let endY = pickerView.selectedRow(inComponent: 4) | ||
let startPoint = CGPoint(x: Double(coordPointValues.value(at: startX)) ?? 0, y: Double(coordPointValues.value(at: startY)) ?? 0) | ||
let endPoint = CGPoint(x: Double(coordPointValues.value(at: endX)) ?? 0, y: Double(coordPointValues.value(at: endY)) ?? 0) | ||
|
||
gView.startPoint = .custom(start: startPoint, end: endPoint) | ||
gView.predefinedGradient = GradientType(rawValue: gradientValues.value(at: pickerView.selectedRow(inComponent: 0))) | ||
gView.configureGradient() | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...tableApp/IBAnimatableApp/Playground/UserInterfaces/Gradients/GradientViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// Created by jason akakpo on 27/07/16. | ||
// Copyright © 2016 IBAnimatable. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import IBAnimatable | ||
|
||
final class GradientViewController: UIViewController { | ||
|
||
@IBOutlet fileprivate weak var gView: AnimatableView! | ||
|
||
let gradientValues = ParamType(fromEnum: GradientType.self) | ||
let startPointValues = ParamType.enumeration(values: ["top", "topLeft", "topRight", "left", "right", "bottom", "bottomRight", "bottomLeft"]) | ||
let colorValues = ParamType(fromEnum: ColorType.self) | ||
var usePredefinedGradient = true | ||
var useRadialGradient = false | ||
lazy var componentValues: [ParamType] = { | ||
self.usePredefinedGradient ? [self.gradientValues, self.startPointValues] : [self.colorValues, self.colorValues, self.startPointValues] | ||
}() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
gView.gradientMode = useRadialGradient ? .radial : .linear | ||
if usePredefinedGradient { | ||
gView.predefinedGradient = GradientType(rawValue: gradientValues.value(at: 0)) | ||
gView.startPoint = GradientStartPoint(string: startPointValues.value(at: 0)) | ||
} else { | ||
gView.startColor = ColorType(rawValue: self.colorValues.value(at: 0))?.color | ||
gView.endColor = ColorType(rawValue: self.colorValues.value(at: 0))?.color | ||
} | ||
let navigationBar = self.navigationController?.navigationBar as? DesignableNavigationBar | ||
navigationBar?.copyGradient(from: gView) | ||
navigationBar?.configureGradient() | ||
} | ||
|
||
override func viewWillDisappear(_ animated: Bool) { | ||
super.viewWillDisappear(animated) | ||
let navigationBar = self.navigationController?.navigationBar as? DesignableNavigationBar | ||
navigationBar?.resetGradient() | ||
navigationBar?.setBackgroundImage(nil, for: .default) | ||
} | ||
|
||
} | ||
|
||
extension GradientViewController: UIPickerViewDelegate, UIPickerViewDataSource { | ||
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { | ||
return componentValues[component].count() | ||
} | ||
|
||
func numberOfComponents(in pickerView: UIPickerView) -> Int { | ||
return componentValues.count | ||
} | ||
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { | ||
let label = UILabel() | ||
label.textColor = .white | ||
label.textAlignment = .center | ||
label.minimumScaleFactor = 0.5 | ||
label.text = componentValues[component].title(at: row) | ||
return label | ||
} | ||
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? { | ||
return componentValues[component].title(at: row).colorize(.white) | ||
} | ||
|
||
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { | ||
if usePredefinedGradient { | ||
gView.predefinedGradient = GradientType(rawValue: gradientValues.value(at: pickerView.selectedRow(inComponent: 0))) | ||
gView.startPoint = GradientStartPoint(string: startPointValues.value(at: pickerView.selectedRow(inComponent: 1))) | ||
} else { | ||
gView.startColor = ColorType(rawValue: self.colorValues.value(at: pickerView.selectedRow(inComponent: 0)))?.color | ||
gView.endColor = ColorType(rawValue: self.colorValues.value(at: pickerView.selectedRow(inComponent: 1)))?.color | ||
gView.startPoint = GradientStartPoint(string: startPointValues.value(at: pickerView.selectedRow(inComponent: 2))) | ||
} | ||
gView.configureGradient() | ||
|
||
let navigationBar = self.navigationController?.navigationBar as? DesignableNavigationBar | ||
navigationBar?.copyGradient(from: gView) | ||
navigationBar?.configureGradient() | ||
} | ||
} | ||
|
||
fileprivate extension GradientDesignable { | ||
|
||
func copyGradient(from designable: GradientDesignable) { | ||
predefinedGradient = designable.predefinedGradient | ||
startColor = designable.startColor | ||
endColor = designable.endColor | ||
startPoint = designable.startPoint | ||
} | ||
|
||
func resetGradient(defaultStartPoint: GradientStartPoint = .top) { | ||
predefinedGradient = nil | ||
startColor = nil | ||
endColor = nil | ||
startPoint = defaultStartPoint | ||
} | ||
|
||
} |
Oops, something went wrong.