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
| // | |
| // VolumeSlider.swift | |
| // TristateToggleProject | |
| // | |
| // Created by Matthew Young on 12/3/19. | |
| // Copyright © 2019 Matthew Young. All rights reserved. | |
| // | |
| // https://stackoverflow.com/questions/58286350/how-to-create-custom-slider-by-using-swiftui |
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 UIView { | |
| var allSubviews: [UIView] { | |
| subviews + subviews.flatMap { $0.allSubviews } | |
| } | |
| func firstSubview<T: UIView>(of type: T.Type) -> T? { | |
| allSubviews.first { $0 is T } as? T |
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 | |
| #if canImport(SwiftUI) && DEBUG | |
| import SwiftUI | |
| struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable { | |
| let viewController: ViewController | |
| init(_ builder: @escaping () -> ViewController) { | |
| viewController = builder() | |
| } |
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
| func downloadAndSaveAudioFile(_ audioFile: String, completion: @escaping (String) -> Void) { | |
| //Create directory if not present | |
| let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.libraryDirectory, FileManager.SearchPathDomainMask.userDomainMask, true) | |
| let documentDirectory = paths.first! as NSString | |
| let soundDirPathString = documentDirectory.appendingPathComponent("Sounds") | |
| do { | |
| try FileManager.default.createDirectory(atPath: soundDirPathString, withIntermediateDirectories: true, attributes:nil) | |
| print("directory created at \(soundDirPathString)") |
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 Foundation | |
| import UIKit | |
| public protocol ReusableView: class { | |
| static var defaultReuseIdentifier: String { get } | |
| } | |
| extension ReusableView where Self: UIView { | |
| public static var defaultReuseIdentifier: String { | |
| return String(describing: self) | |
| } |
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
| // | |
| // This program is free software. It comes without any warranty, to | |
| // the extent permitted by applicable law. You can redistribute it | |
| // and/or modify it under the terms of the Do What The Fuck You Want | |
| // To Public License, Version 2, as published by Sam Hocevar. See | |
| // | |
| // http://sam.zoy.org/wtfpl/COPYING | |
| // | |
| // for more details. | |
| // |
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 Foundation | |
| extension UIView { | |
| func height(constant: CGFloat) { | |
| setConstraint(value: constant, attribute: .height) | |
| } | |
| func width(constant: CGFloat) { | |
| setConstraint(value: constant, attribute: .width) | |
| } |
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 Cocoa | |
| class MyViewController: NSViewController { | |
| var visualEffect: NSVisualEffectView! | |
| override func loadView() { | |
| super.loadView() | |
| visualEffect = NSVisualEffectView() |
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 UITabBarController { | |
| /** | |
| Show or hide the tab bar. | |
| - Parameter hidden: `true` if the bar should be hidden. | |
| - Parameter animated: `true` if the action should be animated. | |
| - Parameter transitionCoordinator: An optional `UIViewControllerTransitionCoordinator` to perform the animation | |
| along side with. For example during a push on a `UINavigationController`. | |
| */ |
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 io | |
| from PIL import Image # https://pillow.readthedocs.io/en/4.3.x/ | |
| import requests # http://docs.python-requests.org/en/master/ | |
| # example image url: https://m.media-amazon.com/images/S/aplus-media/vc/6a9569ab-cb8e-46d9-8aea-a7022e58c74a.jpg | |
| def download_image(url, image_file_path): | |
| r = requests.get(url, timeout=4.0) | |
| if r.status_code != requests.codes.ok: |
NewerOlder