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
// Avoids the keyboard in a UIKit app by leveraging additionalSafeAreaInsets. | |
// You can put this in the root view controller so the whole app will avoid the keyboard. | |
// Only tested on iOS 13.3. | |
// Made for https://douglashill.co/reading-app/ | |
@objc func updateSafeAreaForKeyboardFromNotification(_ notification: Notification) { | |
guard let endFrameInScreenCoords = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { | |
return | |
} | |
// Please consider whether the force unwrap here is safe for your own use case. |
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
/// Performs a textual find and replace with the specified substitutions on all files in directory (recursive) that have the specified filename extensions. | |
func find(_ substitutions: [(find: String, replace: String)], allowedExtensions: Set<String>, directory rootURL: URL) { | |
let fileURLs = FileManager.default.enumerator(at: rootURL, includingPropertiesForKeys: nil)!.map { | |
$0 as! URL | |
} | |
.filter { | |
$0.hasDirectoryPath == false | |
} | |
.filter { | |
allowedExtensions.contains($0.pathExtension) |
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
// Douglas Hill, April 2017 | |
// From https://douglashill.co/reading-app/ | |
#if os(macOS) | |
import AppKit | |
public typealias Colour = NSColor | |
public typealias Font = NSFont | |
public typealias FontDescriptor = NSFontDescriptor | |
public typealias Image = NSImage |
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
// Douglas Hill, December 2019 | |
// Made for https://douglashill.co/reading-app/ | |
import Foundation | |
/// Tries really hard to read a string from a file. | |
/// | |
/// Brute forces encodings if necessary. This will only fail if the file can’t be interpreted | |
/// in any encoding, or if some other error occurs like not being able to read from the file. | |
/// |
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
// Douglas Hill, May 2019 | |
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit | |
import UIKit | |
/// A tab bar controller that allows navigating between tabs using cmd+number on a hardware keyboard. | |
/// So cmd+1 for the first tab, cmd+2 for the second tab etc. | |
public class KeyboardTabBarController: UITabBarController { | |
public override var keyCommands: [UIKeyCommand]? { |
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
// Douglas Hill, November 2019 | |
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit | |
import UIKit | |
/// A scroll view that allows scrolling using a hardware keyboard like `NSScrollView`. | |
/// Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end. | |
/// Limitations: | |
/// - Paging scroll views (isPagingEnabled = true) are not supported yet. | |
/// - The scroll view must become its own delegate so setting the delegate is not supported yet. |
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
@import UIKit; | |
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate> | |
@end | |
@implementation SceneDelegate | |
@synthesize window = _window; | |
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { |
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
import UIKit | |
/// A wrapper view controller that makes the horizontal size class | |
/// be based on both the Dynamic Text size and the width available. | |
class AdaptiveTraitsContainer: UIViewController { | |
let wrappedViewController: UIViewController | |
init(wrappedViewController: UIViewController) { | |
self.wrappedViewController = wrappedViewController | |
super.init(nibName: nil, bundle: nil) |
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
// Douglas Hill, December 2018 | |
// Made for https://douglashill.co/reading-app/ | |
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit | |
import UIKit | |
/// A table view that allows navigation and selection using a hardware keyboard. | |
/// Only supports a single section. | |
class KeyboardTableView: UITableView { | |
// These properties may be set or overridden to provide discoverability titles for key commands. |
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
@implementation PSPDFTableViewCell // UITableViewCell subclass | |
/** | |
On iOS 10, constraints involving a UITableViewCell’s contentView’s layoutMarginsGuide are removed for some | |
reason before the cell appears, which breaks the layout. This layout guide is a working alternative. | |
*/ | |
- (UILayoutGuide *)pspdf_layoutMarginsGuide { | |
if (@available(iOS 11.0, *)) { | |
return self.contentView.layoutMarginsGuide; | |
} |