Skip to content

Instantly share code, notes, and snippets.

@hisoka0917
hisoka0917 / UITableViewController+FixBottomBar.swift
Created June 1, 2018 09:43
UITableViewController with a fixed bottom button
class MyTableViewController: UITableViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
bottomButton.size = CGSize(width: self.view.width, height: 50)
bottomButton.translatesAutoresizingMaskIntoConstraints = false
bottomButton.addTarget(self, action: #selector(bottomButtonClick), for: .touchUpInside)
self.navigationController?.setToolbarHidden(false, animated: animated)
@hisoka0917
hisoka0917 / UIStackView+ReverseSubviews.swift
Last active July 14, 2022 11:15
Reverse UIStackView Arranged Subviews in Z index
extension UIStackView {
func reverseSubviewsZIndex(setNeedsLayout: Bool = true) {
let stackedViews = self.arrangedSubviews
stackedViews.forEach {
self.removeArrangedSubview($0)
$0.removeFromSuperview()
}
@hisoka0917
hisoka0917 / UIView+AnchorPoint.swift
Created July 13, 2018 06:57
Change UIView anchor point in Swift
extension UIView {
func setAnchorPoint(_ point: CGPoint) {
var newPoint = CGPoint(x: bounds.size.width * point.x, y: bounds.size.height * point.y)
var oldPoint = CGPoint(x: bounds.size.width * layer.anchorPoint.x, y: bounds.size.height * layer.anchorPoint.y)
newPoint = newPoint.applying(transform)
oldPoint = oldPoint.applying(transform)
var position = layer.position
@hisoka0917
hisoka0917 / WebViewExampleViewController.swift
Created October 11, 2018 07:13 — forked from fxm90/WebViewExampleViewController.swift
Show progress of WKWebView in UIProgressBar that is attached to an UINavigationBar
//
// WebViewExampleViewController.swift
//
// Created by Felix Mau on 06.01.18.
// Copyright © 2018 Felix Mau. All rights reserved.
//
import UIKit
import WebKit
@hisoka0917
hisoka0917 / Struct2Dictionary.swift
Last active December 23, 2022 03:54
Convert codable struct to dictionary
public protocol RawEnum {
var anyRawValue: Any { get }
}
public extension RawEnum where Self: RawRepresentable {
public var anyRawValue: Any {
get {
let mirror = Mirror(reflecting: self)
if mirror.displayStyle != .enum {
print("WARNING: You can only extend an enum with the Enum protocol")
@hisoka0917
hisoka0917 / SelfAware.swift
Created January 4, 2019 09:21
Self awake code when iOS app launch
import Foundation
import UIKit
protocol SelfAware: class {
static func awake()
}
class ModuleManagerBase {
static func registerModules() {
//let startTime = NSDate.timeIntervalSinceReferenceDate