Skip to content

Instantly share code, notes, and snippets.

View benguild's full-sized avatar

Ben Guild benguild

View GitHub Profile
@benguild
benguild / ContentUnavailableView+Backport.swift
Created February 28, 2025 07:31
This seems like a fairly accurate (yet incomplete) "backport" of `ContentUnavailableView` from iOS 17 to iOS 16.
import SwiftUI
@available(iOS 16, *)
struct ContentUnavailableView<Label: View, Description: View>: View {
private struct VerticalLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
VStack(spacing: -1) {
configuration.icon
.font(.system(size: 48))
.foregroundColor(.secondary)
private func cameraPreviewObfuscationImage(from image: CIImage, with blurRadius: CGFloat, at targetSize: CGSize) -> UIImage? {
var blurAdjustedTargetSize = targetSize
if targetSize.width > targetSize.height {
blurAdjustedTargetSize.height += blurRadius * 2
} else {
blurAdjustedTargetSize.width += blurRadius * 2
}
let croppedImage = image.cropped(to: AVMakeRect(aspectRatio: blurAdjustedTargetSize, insideRect: image.extent))
@benguild
benguild / topmostViewControllerForFrontmostNormalLevelWindow.m
Last active March 4, 2022 04:26
Block for finding topmost `UIViewController` of frontmost normal-level `UIWindow`.
UIViewController *(^topmostViewControllerForFrontmostNormalLevelWindow)(void) = ^UIViewController *{
// NOTE: Adapted from various stray answers here:
// https://stackoverflow.com/questions/6131205/iphone-how-to-find-topmost-view-controller/20515681
UIViewController *viewController;
for (UIWindow *window in UIApplication.sharedApplication.windows.reverseObjectEnumerator.allObjects) {
if (window.windowLevel == UIWindowLevelNormal) {
viewController = window.rootViewController;
break;
@benguild
benguild / UIImage+QRCode.h
Last active February 8, 2019 04:50
Properly scaled QR Code generator class method for `UIImage` (lightweight, avoids anti-aliasing/blurring)
//
// UIImage+QRCode.h
//
// Created by Ben Guild on 2017/09/17.
// Copyright © 2017年 Ben Guild. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIImage (QRCode)