Skip to content

Instantly share code, notes, and snippets.

@wb-towa
wb-towa / RelativeSizeLayout.swift
Created March 24, 2023 07:23 — forked from ole/RelativeSizeLayout.swift
A SwiftUI layout and modifier for working with relative sizes ("50 % of your container"). https://oleb.net/2023/swiftui-relative-size/
import SwiftUI
extension View {
/// Proposes a percentage of its received proposed size to `self`.
///
/// This modifier multiplies the proposed size it receives from its parent
/// with the given factors for width and height.
///
/// If the parent proposes `nil` or `.infinity` to us in any dimension,
/// we’ll forward these values to our child view unchanged.
@wb-towa
wb-towa / AttributedString.swift
Created March 19, 2023 17:32 — forked from chockenberry/AttributedString.swift
A playground that shows how to use Swift's AttributedString with Markdown
import UIKit
import Foundation
// NOTE: This playground shows how to use Swift's AttributedString with Markdown.
//
// This code was used to display Markdown content in the Tot iOS Widget <https://tot.rocks>
// MARK: - Helpful Links
// NOTE: The following links helped me figure this stuff out.
@wb-towa
wb-towa / FreeSpaceViewController.swift
Created October 8, 2022 10:23 — forked from kylehowells/FreeSpaceViewController.swift
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 {
@wb-towa
wb-towa / Setup.swift
Created May 26, 2022 09:47 — forked from DavidPiper94/Setup.swift
Example code for article about section index - Setup of UITableView
class ViewController: UIViewController {
// 1
@IBOutlet weak var tableView: UITableView!
// 2
let sectionTitles = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".map(String.init)
}
extension ViewController: UITableViewDataSource {
@wb-towa
wb-towa / playground.swift
Created May 26, 2022 09:46 — forked from BrandonShega/playground.swift
Table View Section Index List
//: Playground - noun: a place where people can play
import UIKit
import Foundation
import PlaygroundSupport
let allStates = ["Alaska",
"Alabama",
"Arkansas",
"American Samoa",
import SwiftUI
struct ContentView: View {
@State var pictureExpanded = false
var body: some View {
VStack(alignment: .leading, spacing: 20.0) {
Text("Once upon a time there was a turtle named George who made friends with a giraffe at the local water park and then they went on lots of adventures together.")
Button {
@wb-towa
wb-towa / healthkit-async-await-workouts.swift
Created January 28, 2022 09:26 — forked from tshortli/healthkit-async-await-workouts.swift
A Swift async function that gets the most recent workouts from HealthKit
func mostRecentWorkouts(for healthStore: HKHealthStore, limit: Int) async throws -> [HKWorkout] {
let query = HKSampleQueryDescriptor(
predicates: [.workout()],
sortDescriptors: [SortDescriptor(\.endDate, order: .reverse)],
limit: limit
)
return try await query.result(for: healthStore)
}
import UIKit
extension UITextField {
/// Add a trailing placeholder label that tracks the text as it changes
func addTrailingPlaceholder(_ placeholder: String) {
let label = UILabel()
label.text = placeholder
label.alpha = 0.3
label.isHidden = true
addSubview(label)
@wb-towa
wb-towa / SwiftUI Tagger.swift
Created November 29, 2021 21:57 — forked from mralexhay/SwiftUI Tagger.swift
A SwiftUI interface for adding tags
//
// TaggerView.swift
//
// Created by Alex Hay on 21/11/2020.
//
// Simple interface for adding tags to an array in SwiftUI
// Example video: https://imgur.com/gallery/CcA1IXp
// alignmentGuide code from Asperi @ https://stackoverflow.com/a/58876712/11685049
import SwiftUI
@wb-towa
wb-towa / convert.swift
Created August 13, 2021 15:56 — forked from SatoTakeshiX/convert.swift
Take capture a view by SwiftUI
//
// ContentView.swift
// TryGeometryReader
//
// Created by satoutakeshi on 2019/12/07.
// Copyright © 2019 satoutakeshi. Licensed under MIT.
//
import SwiftUI