Skip to content

Instantly share code, notes, and snippets.

View shawn-frank's full-sized avatar

Shawn Frank shawn-frank

View GitHub Profile
@shawn-frank
shawn-frank / UITableViewConvenience.swift
Last active March 14, 2021 18:04
Some lines of code for common customizations required for UITableView and UITableViewCell yet easy to forget
// Remove seperator lines between UITableViewCells in UITableView
// Reference: https://stackoverflow.com/questions/26653883/delete-lines-between-uitableviewcells-in-uitableview
var tableView = UITableView()
tableView.separatorStyle = .none
// Add spacing between UITableViewCell
// Reference: https://stackoverflow.com/questions/1369831/eliminate-extra-separators-below-uitableview
// Inside UITableViewCell subclass
override func layoutSubviews() {
super.layoutSubviews()
@shawn-frank
shawn-frank / ExampleClass.swift
Created March 14, 2021 18:03
Simplest Way to Add Stored Property to Swift Extension
// Reference and credit: https://dzone.com/articles/simplest-way-to-add-stored-property-to-swift-exten
class ExampleClass {}
fileprivate var storedProperty_FILEPRIVATE: [ObjectIdentifier:Int] = [:]
fileprivate var storedProperty_DEFAULT: Int = 0
extension ExampleClass {
var storedProperty: Int {
get {return storedProperty_FILEPRIVATE[ObjectIdentifier(self)] ?? storedProperty_DEFAULT}
set {storedProperty_FILEPRIVATE[ObjectIdentifier(self)] = newValue}
@shawn-frank
shawn-frank / UITableViewHeader.swift
Last active February 8, 2023 00:45
UITableViewHeader
//
// UITableViewHeaderSectionView.swift
// Site Visit
//
// Created by Shawn Frank on 10/06/2021.
//
import UIKit
class UITableViewHeaderSectionView: UITableViewHeaderFooterView {
// REF: https://stackoverflow.com/a/62787968/1619193
private func configureNavBar() {
navigationBar.standardAppearance.backgroundColor = UIColor.clear
navigationBar.standardAppearance.backgroundEffect = nil
navigationBar.standardAppearance.shadowImage = UIImage()
navigationBar.standardAppearance.shadowColor = .clear
navigationBar.standardAppearance.backgroundImage = UIImage()
}
private func configureNavBar2() {
@shawn-frank
shawn-frank / InputViewController.swift
Created February 16, 2022 17:01
A UITableView with editable UITextFields in UITableView cells that change based on the value of another
//
// InputViewController.swift
// TestApp
//
// Created by Shawn Frank on 30/01/2022.
//
import UIKit
// Your model to store data in text fields
@shawn-frank
shawn-frank / NewsTableViewVC.swift
Created February 16, 2022 17:39
Set up a UITableView to get the default animation when working with a UISearchController like seen in the Apple iOS News app
//
// NewsTableViewVC.swift
// TestApp
//
// Created by Shawn Frank on 16/02/2022.
//
import UIKit
fileprivate class CustomCell: UITableViewCell
@shawn-frank
shawn-frank / UnderlineString.playground
Last active March 7, 2022 03:23
This is a playground example of how to underline text that occurs a specified number of times in response to this stack overflow question: https://stackoverflow.com/q/71359204/1619193
import UIKit
struct MatchProperty
{
// Stores the index of the iCor array the current
// word belongs to
var iCorRIndex: Int
// Stores the index of the sentence in the which the word
// was encountered in the current iCor array
@shawn-frank
shawn-frank / SwipeCollectionView.swift
Created March 18, 2022 10:30
A small example of using a UIPanGestureRecognizer to swipe up and bring a UICollectionView interaction. This was created as a demo to this StackOverflow question: https://stackoverflow.com/q/71304657/1619193
//
// SwipeCollectionView.swift
// TestApp
//
// Created by Shawn Frank on 01/03/2022.
//
import UIKit
class SwipeCollectionView: UIViewController
@shawn-frank
shawn-frank / CustomLayoutVC.swift
Created March 21, 2022 17:03
This is an example of creating a custom UICollectionViewFlowLayout with a decoration view in order to give each section a border for iOS using Swift. This was in response to this stack overflow question: https://stackoverflow.com/questions/71552265/is-there-a-way-to-give-outer-border-in-every-section-of-uicollctionview?noredirect=1#comment126463…
//
// CustomLayoutVC.swift
// TestApp
//
// Created by Shawn Frank on 21/03/2022.
//
import UIKit
// This is used as the header and footer of each section
@shawn-frank
shawn-frank / SegmentCollectionViewVC.swift
Created March 22, 2022 10:56
This is an example of using a UICollectionView to create a custom segment control. This example shows a strategy to resize a UILabel's font so that it fits within the frame provided. This sample code is for iOS using Swift and was created in response to this stack overflow question: https://stackoverflow.com/q/71566815/1619193
//
// SegmentCollectionViewVC.swift
// TestApp
//
// Created by Shawn Frank on 22/03/2022.
//
import UIKit
fileprivate class SegmentCell: UICollectionViewCell {