Skip to content

Instantly share code, notes, and snippets.

//
// TappableUILabelDemoViewController.swift
// Label Link Test
//
// Created by Kyle Howells on 2024-03-20.
//
import UIKit
@kylehowells
kylehowells / Tap links in UILabel.swift
Created March 20, 2024 01:24
Tap Links in UILabel
@kylehowells
kylehowells / CBManagerAuthorization+String.swift
Created March 9, 2023 01:18
Debug strings for CBManagerAuthorization
import Foundation
import CoreBluetooth
extension CBManagerAuthorization : CustomDebugStringConvertible {
public var debugDescription: String {
switch self {
case .allowedAlways: return "allowedAlways"
case .denied: return "denied"
case .notDetermined: return "notDetermined"
@kylehowells
kylehowells / WaveView.swift
Created February 25, 2023 23:27
Animates a wave ripple along the top
import UIKit
// MARK: - WaveView
class WaveView: UIView {
private var shapeLayer: CAShapeLayer = CAShapeLayer()
// MARK: - Animation Properties
import SceneKit
struct SceneKitBoundingBox {
let backLeftTop: SCNVector3
let backLeftBottom: SCNVector3
let backRightTop: SCNVector3
let backRightBottom: SCNVector3
let frontLeftTop: SCNVector3
import UIKit
extension UIResponder {
private weak static var _currentFirstResponder: UIResponder? = nil
public static var current: UIResponder? {
UIResponder._currentFirstResponder = nil
UIApplication.shared.sendAction(#selector(findFirstResponder(sender:)), to: nil, from: nil, for: nil)
return UIResponder._currentFirstResponder
}
private func AVMakeRectFill(aspectRatio: CGSize, insideRect boundingRect: CGRect) -> CGRect {
let targetSize = boundingRect.size
if targetSize == .zero {
return .zero
}
let widthRatio = targetSize.width / aspectRatio.width
let heightRatio = targetSize.height / aspectRatio.height
let scalingFactor = max(widthRatio, heightRatio)
@kylehowells
kylehowells / MP4Exporter.swift
Created July 3, 2022 03:56
Export UIView as MP4 in Swift using AVFoundation AVAssetWriter
//
// MP4Exporter.swift
// Code Examples
//
// Created by Kyle Howells on 03/07/2022.
//
import Foundation
import UIKit
import AVFoundation
import CoreGraphics
import UIKit
import AVFoundation
extension UIImage {
func resized(within newSize: CGSize, outputScale: CGFloat? = nil) -> UIImage {
let originalSize = self.size
let withinBounds = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)
@kylehowells
kylehowells / FreeSpaceViewController.swift
Created May 4, 2022 23:24
UIViewController subclass to show both the Settings app displayed free space, and the real free space.
//
// FreeSpaceViewController.swift
// Free Space
//
// Created by Kyle Howells on 04/05/2022.
//
import UIKit
class FreeSpaceViewController: UIViewController {