Skip to content

Instantly share code, notes, and snippets.

View froggomad's full-sized avatar

Kenny Dubroff (froggomad) froggomad

View GitHub Profile
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
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
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
import UIKit
class InstructionViewController: UIViewController {
var titleText: String
var instructions: String
var image: UIImage
var caption: String?
var buttonTitle: String
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
class AlertView: UIView {
@IBOutlet var closeButton: UIButton!
@IBAction func close(_ sender: UIButton) {
TapticEngine.pop()
flash(closeButton) { [weak self] _ in
self?.removeFromSuperview()
}
}
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)
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)
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)
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
}()