Skip to content

Instantly share code, notes, and snippets.

@olKull
olKull / Switch.swift
Created November 23, 2020 09:00 — forked from nathantannar4/Switch.swift
Re-Engineering UISwitch
//
// Switch.swift
// Re-Engineering UISwitch
//
// Created by Nathan Tannar on 15/12/18.
// Copyright © 2018 Nathan Tannar. All rights reserved.
//
import UIKit
@olKull
olKull / CGFloat+normalization.swift
Created August 31, 2020 13:28 — forked from mcichecki/CGFloat+normalization.swift
Normalized value of CGFloat between two values
extension CGFloat {
func normalize(min: CGFloat, max: CGFloat, from a: CGFloat = 0, to b: CGFloat = 1) -> CGFloat {
return (b - a) * ((self - min) / (max - min)) + a
}
}
@olKull
olKull / UITextViewPlaceholder.swift
Created August 24, 2020 16:25 — forked from tijme/UITextViewPlaceholder.swift
The correct way to implement a placeholder in a UITextView (Swift)
//
// UITextViewPlaceholder.swift
// TextViewPlaceholder
//
// Copyright (c) 2017 Tijme Gommers <tijme@finnwea.com>
//
// 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
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@IBDesignable
public class Gradient: UIView {
@IBInspectable var startColor: UIColor = .black { didSet { updateColors() }}
@IBInspectable var endColor: UIColor = .white { didSet { updateColors() }}
@IBInspectable var startLocation: Double = 0.05 { didSet { updateLocations() }}
@IBInspectable var endLocation: Double = 0.95 { didSet { updateLocations() }}
@IBInspectable var horizontalMode: Bool = false { didSet { updatePoints() }}
@IBInspectable var diagonalMode: Bool = false { didSet { updatePoints() }}
override public class var layerClass: AnyClass { CAGradientLayer.self }
@olKull
olKull / animation.swift
Last active June 16, 2020 11:32
iOS animation button
extension UIButton {
func pulsate() {
let pulse = CASpringAnimation(keyPath: "transform.scale")
pulse.duration = 0.2
pulse.fromValue = 0.95
pulse.toValue = 1.0
pulse.autoreverses = true
pulse.repeatCount = 2
@olKull
olKull / Userdefaults.swift
Created May 22, 2020 08:09
An effective way to clear entire Userdefaults in Swift
UserDefaults.standard.removeObject(forKey: "is_app_launched")
extension UserDefaults {
static func resetDefaults() {
if let bundleID = Bundle.main.bundleIdentifier {
UserDefaults.standard.removePersistentDomain(forName: bundleID)
}
}
}
@olKull
olKull / transparentNavigationBar.swift
Created May 4, 2020 20:59
How to set transparent navigation bar.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// navigationController?.setNavigationBarHidden(true, animated: true)
guard self.navigationController?.topViewController === self else { return }
self.transitionCoordinator?.animate(alongsideTransition: { [weak self](context) in
self?.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self?.navigationController?.navigationBar.shadowImage = UIImage()
self?.navigationController?.navigationBar.backgroundColor = .clear
@olKull
olKull / database_config.php
Last active May 4, 2020 20:50
MAC OS MAMP App - Laravel database config
<?php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',