Skip to content

Instantly share code, notes, and snippets.

View bananafish911's full-sized avatar
👽

Victor Do. bananafish911

👽
View GitHub Profile
@vinczebalazs
vinczebalazs / SheetModalPresentationController.swift
Last active January 9, 2023 23:02
SheetModalPresentationController.swift
import UIKit
final class SheetModalPresentationController: UIPresentationController {
// MARK: Private Properties
private let isDismissable: Bool
private let interactor = UIPercentDrivenInteractiveTransition()
private let dimmingView = UIView()
private var propertyAnimator: UIViewPropertyAnimator!
@vinczebalazs
vinczebalazs / SheetModalPresentationController.swift
Last active February 1, 2024 04:40
A presentation controller to use for presenting a view controller modally, which can be dismissed by a pull down gesture. The presented view controller's height is also adjustable.
import UIKit
extension UIView {
var allSubviews: [UIView] {
subviews + subviews.flatMap { $0.allSubviews }
}
func firstSubview<T: UIView>(of type: T.Type) -> T? {
allSubviews.first { $0 is T } as? T
@WorldDownTown
WorldDownTown / InsertRowsWithoutScrollingViewController.swift
Last active September 27, 2023 06:26
Insert rows in the top of UITableView without scrolling.
import UIKit
final class ViewController: UITableViewController {
private var names: [String] = (50...99).map { String($0) }
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
@vdugnist
vdugnist / uiimage_check.sh
Last active February 11, 2021 06:42
Check if UIImage exists in assets
#!/bin/bash
CLASSES_FOLDERS=($PROJECT_NAME)
RESOURCE_FOLDER=$PROJECT_NAME
function show_code {
for ClassFolder in "${CLASSES_FOLDERS[@]}"; do
# try to find image name in [UIImage imageNamed:] pattern
ERROR_LOCATION=$(grep -Ron "\[UIImage imageNamed:@\"$1\"]" $ClassFolder)
if [[ -n $ERROR_LOCATION ]]; then break; fi;
@avdyushin
avdyushin / storage.swift
Last active August 28, 2023 14:35
CoreData stack for iOS 9 and iOS 10 using Swift 3
//
// Storage.swift
//
// Created by Grigory Avdyushin on 30.06.16.
// Copyright © 2016 Grigory Avdyushin. All rights reserved.
//
import UIKit
import CoreData
extension PHPhotoLibrary {
typealias PhotoAsset = PHAsset
typealias PhotoAlbum = PHAssetCollection
static func saveImage(image: UIImage, albumName: String, completion: (PHAsset?)->()) {
if let album = self.findAlbum(albumName) {
saveImage(image, album: album, completion: completion)
return
}
@vovkasm
vovkasm / SnapshotHelper.h
Last active June 30, 2021 06:55
Objective C implementation of SnapshotHelper class for Fastline Snapshot tool (https://github.com/fastlane/fastlane/tree/master/snapshot).
/* This SnapshotHelper class should be compatible with SnapshotHelper.swift version 1.2 */
@import Foundation;
@import XCTest;
@interface SnapshotHelper : NSObject
- (instancetype)initWithApp:(XCUIApplication*)app;
- (void)snapshot:(NSString*)name waitForLoadingIndicator:(BOOL)wait;
@nbasham
nbasham / UIColor.swift
Last active December 18, 2023 21:04
Swift 4: Convert CSS color names and RGB hex values to UIColor. UIColor from hex 3, 4, 6, and 8 characters in length with or without # prefix. UIColor to hex. UIColor extension that creates immutable UIColor instances from hexadecimal and CSS color name strings (e.g. ff0, #f00, ff0000, ff0000ff, Pink, aZure, CLEAR, nil). Conversely, you can obta…
//
// UIColor.swift
// previously Color+HexAndCSSColorNames.swift
//
// Created by Norman Basham on 12/8/15.
// Copyright ©2018 Black Labs. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@kaloprominat
kaloprominat / xcode objective-c GCD dispatch group wait example
Last active August 5, 2023 10:50
xcode objective-c GCD dispatch group wait example
//first
dispatch_async(queue, ^{
dispatch_group_t group1 = dispatch_group_create();
// Tasks goes here
for (NSInteger i = 0; i < 3; i++) {
@marcboeren
marcboeren / 1.UIStoryboardSegueFromRight.swift
Created March 19, 2015 20:02
Segue from Right (Slide the next controllers view in from right to left (and back))
import UIKit
class UIStoryboardSegueFromRight: UIStoryboardSegue {
override func perform()
{
let src = self.sourceViewController as UIViewController
let dst = self.destinationViewController as UIViewController
src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)