Skip to content

Instantly share code, notes, and snippets.

View CristianMoisei's full-sized avatar

Cristian Moisei CristianMoisei

View GitHub Profile
@ricardopereira
ricardopereira / GradientLayer + Mask + TableView.swift
Last active July 19, 2023 16:59
Apply vertical mask alpha gradient to UITableView
let gradient = CAGradientLayer()
gradient.frame = tableView.superview?.bounds ?? CGRectNull
gradient.colors = [UIColor.clearColor().CGColor, UIColor.clearColor().CGColor, UIColor.blackColor().CGColor, UIColor.blackColor().CGColor, UIColor.clearColor().CGColor, UIColor.clearColor().CGColor]
gradient.locations = [0.0, 0.15, 0.25, 0.75, 0.85, 1.0]
tableView.superview?.layer.mask = gradient
tableView.backgroundColor = UIColor.clearColor()
@leakypixel
leakypixel / always-mobile-wikipedia.js
Last active May 26, 2019 22:19
UserScript: Redirect desktop Wikipedia to mobile
// ==UserScript==
// @name always_mobile_wikipedia
// @namespace https://gist.github.com/leakypixel
// @description Redirect desktop Wikipedia to mobile
// @author leakypixel
// @include http://*.wikipedia.org/*
// @include https://*.wikipedia.org/*
// @version 0.2
// @grant none
// ==/UserScript==
@TheCodedSelf
TheCodedSelf / Disable Alert Button.swift
Last active March 31, 2024 18:00
Disable Alert Controller button if Alert Controller text field is empty or whitespace
import UIKit
// Create an alert controller
let alertController = UIAlertController(title: "Alert", message: "Please enter text", preferredStyle: .alert)
// Create an OK Button
let okAction = UIAlertAction(title: "OK", style: .default) { (_) in
// Print "OK Tapped" to the screen when the user taps OK
print("OK Tapped")
}
@henning-jh
henning-jh / *.swift
Last active November 29, 2022 20:42
Sign In with Apple: presentation anchor
extension MyLoginViewController: ASAuthorizationControllerPresentationContextProviding {
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return self.view.window!
}
}
extension String {
func foregroundColor(_ color: UIColor) -> NSAttributedString {
NSAttributedString(string: self, attributes: [.foregroundColor : color])
}
func background(_ color: UIColor) -> NSAttributedString {
NSAttributedString(string: self, attributes: [.backgroundColor: color])
}
func underline(_ color: UIColor, style: NSUnderlineStyle = .single) -> NSAttributedString {
NSAttributedString(string: self, attributes: [.underlineColor: color, .underlineStyle: style.rawValue])
}
@atereshkov
atereshkov / swift-5-resumable-timer.swift
Created August 19, 2019 14:39
Swift 5 Resumable Timer
class ResumableTimer: NSObject {
private var timer: Timer? = Timer()
private var callback: () -> Void
private var startTime: TimeInterval?
private var elapsedTime: TimeInterval?
// MARK: Init
@artemnovichkov
artemnovichkov / UserDefaults+InterfaceStyle.swift
Last active December 25, 2022 12:30
Saving UIUserInterfaceStyle to UserDefaults
public extension UserDefaults {
var overridedUserInterfaceStyle: UIUserInterfaceStyle {
get {
UIUserInterfaceStyle(rawValue: integer(forKey: #function)) ?? .unspecified
}
set {
set(newValue.rawValue, forKey: #function)
}
}