This file contains hidden or 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
import UIKit | |
class ViewControllerView: UIView { | |
private lazy var buttonStack: UIStackView = { | |
let stack = UIStackView(arrangedSubviews: [viewButton, alertButton]) | |
stack.translatesAutoresizingMaskIntoConstraints = false | |
stack.spacing = 12 | |
stack.axis = .vertical | |
return stack |
This file contains hidden or 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
import UIKit | |
extension UIColor { | |
// credit: @beyowulf | |
// https://stackoverflow.com/questions/47365583/determining-text-color-from-the-background-color-in-swift/47366748 | |
var isDarkColor: Bool { | |
var r, g, b, a: CGFloat | |
(r, g, b, a) = (0, 0, 0, 0) | |
self.getRed(&r, green: &g, blue: &b, alpha: &a) | |
let lum = 0.2126 * r + 0.7152 * g + 0.0722 * b |
This file contains hidden or 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
class InstructionView: UIView { | |
private var titleString: String | |
private var instructions: String | |
private var image: UIImage | |
private var caption: String? | |
private var buttonTitle: String | |
private var target: Any? | |
private var selector: Selector | |
This file contains hidden or 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
import UIKit | |
class InstructionViewController: UIViewController { | |
var titleText: String | |
var instructions: String | |
var image: UIImage | |
var caption: String? | |
var buttonTitle: String | |
This file contains hidden or 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
import AudioToolbox.AudioServices | |
enum TapticEngine: UInt32 { | |
/// 'Peek' feedback (single weak boom) | |
case peek = 1519 | |
/// 'Pop' feedback (single strong boom) | |
case pop = 1520 | |
/// 'Cancelled' feedback (three sequential weak booms) | |
case cancelled = 1521 | |
/// provide haptic feedback to the user |
This file contains hidden or 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
class AlertView: UIView { | |
@IBOutlet var closeButton: UIButton! | |
@IBAction func close(_ sender: UIButton) { | |
TapticEngine.pop() | |
flash(closeButton) { [weak self] _ in | |
self?.removeFromSuperview() | |
} | |
} | |
This file contains hidden or 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
import AudioToolbox.AudioServices | |
class TapticEngine { | |
/// 'Peek' feedback (single weak boom) | |
static func peek() { | |
AudioServicesPlaySystemSound(1519) | |
} | |
/// 'Pop' feedback (single strong boom) | |
static func pop() { | |
AudioServicesPlaySystemSound(1520) |
This file contains hidden or 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
import AudioToolbox.AudioServices | |
class TapticEngine { | |
/// 'Peek' feedback (single weak boom) | |
static func peek() { | |
AudioServicesPlaySystemSound(1519) | |
} | |
/// 'Pop' feedback (single strong boom) | |
static func pop() { | |
AudioServicesPlaySystemSound(1520) |
This file contains hidden or 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
extension TitledCollectionView: UICollectionViewDelegate { | |
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
updateControllerDelegate(with: indexPath.item) | |
} | |
private func updateControllerDelegate(with item: Int) { | |
switch self.produce { | |
case .fruit: | |
let fruit = Fruit.allCases[item] | |
print(produce?.description, fruit.description) |
This file contains hidden or 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
private lazy var collectionView: UICollectionView = { | |
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: Layout()) | |
collectionView.register(ProduceCollectionViewCell.self, forCellWithReuseIdentifier: ProduceCollectionViewCell.identifier) | |
collectionView.dataSource = self | |
collectionView.translatesAutoresizingMaskIntoConstraints = false | |
return collectionView | |
}() |