Skip to content

Instantly share code, notes, and snippets.

//
// UITestCase.swift
//
// Created by Gleb Tarasov on 23/04/2018.
//
import Foundation
import XCTest
import UIKit
@simme
simme / UITabBarController+ToggleTabBar.swift
Created January 25, 2018 15:36
Extension on UITabBarController for hiding/showing the tab bar.
extension UITabBarController {
/**
Show or hide the tab bar.
- Parameter hidden: `true` if the bar should be hidden.
- Parameter animated: `true` if the action should be animated.
- Parameter transitionCoordinator: An optional `UIViewControllerTransitionCoordinator` to perform the animation
along side with. For example during a push on a `UINavigationController`.
*/
@siemensikkema
siemensikkema / fixcodeproj.rb
Last active April 15, 2021 14:06
Post processing script for generated vapor Xcode project
#!/usr/bin/env ruby
require 'xcodeproj'
project_path = ARGV[0]
project = Xcodeproj::Project.open(project_path)
project.targets.each do |target|
# suppress warnings
if [
"Configs",
@krodak
krodak / Realm+CascadeDeleting.swift
Last active April 27, 2023 19:16
Cascade deletion for RealmSwift
import RealmSwift
import Realm
protocol CascadeDeleting: class {
func delete<Entity>(_ list: List<Entity>, cascading: Bool)
func delete<Entity>(_ results: Results<Entity>, cascading: Bool)
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
@lyamamot
lyamamot / generate_app_icons.sh
Created August 9, 2017 16:29
Generate placeholder icons for iOS apps that indicate their own size (in pixels).
#!/bin/bash
# https://developer.apple.com/library/content/qa/qa1686/_index.html
function create_image() {
COLOR=$1
TEXT_COLOR=$2
SIZE=$3
NAME=$4
convert -background "$COLOR" -fill white -font "Tahoma" -size $SIZEx$SIZE label:$SIZE "$NAME"
@vinhnx
vinhnx / uicollectionview+fade.md
Last active February 24, 2022 18:58
Collection view cell fade as scrolling effect

// reference: https://stackoverflow.com/a/42705208/1477298

You can do a lot of fun stuff to collection views. I like to subclass UICollectionViewFlowLayout. Here is an example that fades the top and the bottom of the collection view based on distance from center. I could modify it to fade only the very edges but you should figure it after you look through the code.

import UIKit

class FadingLayout: UICollectionViewFlowLayout,UICollectionViewDelegateFlowLayout {

    //should be 0<fade<1
@sgr-ksmt
sgr-ksmt / StoryboardInstantiatable.swift
Last active October 12, 2023 09:11
Create UIViewController from storyboard and pass parameter safely.
public protocol StoryboardInstantiatable {
static var storyboardName: String { get }
static var viewControllerIdentifier: String? { get }
static var bundle: Bundle? { get }
}
public extension StoryboardInstantiatable where Self: UIViewController {
public static var storyboardName: String {
return String(describing: self)
}
@roymckenzie
roymckenzie / KeyboardAvoidable.swift
Last active September 6, 2022 19:42
Easy way to get your view controllers to respect appearance of the keyboard.
// KeyboardAvoidable
// Roy McKenzie
protocol KeyboardAvoidable: class {
func addKeyboardObservers(customBlock: ((CGFloat) -> Void)?)
func removeKeyboardObservers()
var layoutConstraintsToAdjust: [NSLayoutConstraint] { get }
}
var KeyboardShowObserverObjectKey: UInt8 = 1
//
// CameraViewController.swift
// Camera
//
// Created by Stephen Gurnett on 03/01/2016.
// Copyright © 2016 Stephen Gurnett. All rights reserved.
//
import UIKit
import MobileCoreServices
@calt
calt / Tabbar.Swift
Last active April 22, 2025 05:34
UITabBar with custom height in Swift, does not work for iOS 14 or later.
// Does not work on iOS 14.0 or later, keeping the gist just for reference.
extension UITabBar {
override open func sizeThatFits(size: CGSize) -> CGSize {
super.sizeThatFits(size)
var sizeThatFits = super.sizeThatFits(size)
sizeThatFits.height = 71
return sizeThatFits
}
}