Skip to content

Instantly share code, notes, and snippets.

@DonMag
DonMag / ContentSizeViewController.swift
Created March 4, 2023 16:08
Testing .contentSize in UIScrollView
//
// Created by Don Mag on 3/4/23.
//
import UIKit
class ContentSizeViewController: UIViewController, UIScrollViewDelegate {
let scrollView = UIScrollView()
@DonMag
DonMag / ViewController.swift
Created February 2, 2023 15:10
Simple Swift example of adding Child View Controllers
class ViewController: UIViewController {
let infoLabel = UILabel()
let stack = UIStackView()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemYellow
//
// SlowLabelViewController.swift
//
// Created by Don Mag on 12/14/22.
//
// Demonstrates how slow UILabel rendering when using High-Unicode strings
class SlowLabelViewController: UIViewController {
var lowAsciiStr: String = ""
@DonMag
DonMag / CollectionViewInTableViewCell.swift
Created June 16, 2022 13:46
Basic Swift iOS example of collection view in a table view cell
// assign table view controller custom class to:
// DonMagSampleTableViewController
// no cell Prototypesneeded
// no @IBOutlet or @IBAction connections needed
struct DonMagSampleDataStruct {
var color: UIColor = .white
var strings: [String] = []
}
class NewPopupTestViewController: UIViewController {
let popupView = PopupView()
let testMessages: [String] = [
"Short Message",
"A Longer Message",
"A Sample Message that is long enough it will need to wrap onto multiple lines.",
]
var testIDX: Int = 0
@DonMag
DonMag / StepRecording.swift
Created March 23, 2022 19:42
Three approaches to multi-color "sectioned" view
// three different ways (among many) to implement a multi-colored progress- or slider-style view.
struct RecordingStep {
var color: UIColor = .black
var start: Float = 0
var end: Float = 0
// layer is used only with MultiLayerStepView
var layer: CALayer!
}
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="wEY-jX-xfc">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
// generate a PDF with
// a 6-inch vertical line crossed by a 6-inch horizontal line
// vertical and horizontal "1-inch hash" lines
// 6-, 4- and 2-inch diameter circles
// see app image here: https://imgur.com/a/O9dmB9M
import PDFKit
class ViewController: UIViewController {
@IBDesignable
class IntrinsicHeightLabel: UILabel {
@IBInspectable
var h: CGFloat = 0
override var intrinsicContentSize: CGSize {
let sz = super.intrinsicContentSize
if h == 0 {
return sz
class TestFilterViewController: UIViewController {
let sepiaSharpenBlurImageView: UIImageView = {
let v = UIImageView()
v.contentMode = .scaleAspectFit
return v
}()
let sepiaBlurSharpenImageView: UIImageView = {
let v = UIImageView()