Skip to content

Instantly share code, notes, and snippets.

View stleamist's full-sized avatar

Dongkyu Kim (Max.kim) stleamist

View GitHub Profile
@stleamist
stleamist / UIBlurEffect+CustomBlurEffect.swift
Last active July 15, 2020 14:26
UIBlurEffect with custom blur radius
import UIKit
extension UIBlurEffect {
@available(iOS 9.0, *)
static func customBlurEffect(blurRadius: CGFloat) -> UIBlurEffect {
let UICustomBlurEffect = NSClassFromString("_UICustomBlurEffect") as! UIBlurEffect.Type
let customBlurEffect = UICustomBlurEffect.init()
customBlurEffect.setValue(blurRadius, forKey: "blurRadius")
import Foundation
public extension Encodable {
func jsonString(options: JSONEncoder.OutputFormatting = .prettyPrinted) -> String? {
let encoder = JSONEncoder()
encoder.outputFormatting = options
guard let jsonStringData = try? encoder.encode(self) else {
return nil
}
import UIKit
extension UIDevice {
var hasHomeIndicatorArea: Bool? {
// AppDelegate에서 window의 makeKeyAndVisible()이 호출되기 전에는 keyWindow 프로퍼티가 nil 값을 반환하므로,
// 그 전에는 AppDelegate window 프로퍼티를 가져오도록 한다.
guard let window: UIWindow = UIApplication.shared.keyWindow ?? UIApplication.shared.delegate?.window ?? nil else {
return nil
}
let bottomSafeAreaInsets = window.safeAreaInsets.bottom
import sys, plistlib, json, re, subprocess
from datetime import datetime as dt
from datetime import timedelta
import urllib.parse as up
def dequote(path):
if (path[0] == path[-1]) and path.startswith(("'", '"')):
return path[1:-1]
else:
return path

List of iOS Card Sheet Controllers

@stleamist
stleamist / UIButton+BackgroundColor.swift
Last active June 26, 2022 05:52
An UIButton extension to set the color of its background, supporting dynamic colors introduced in iOS 13.
//
// UIButton+BackgroundColor.swift
// An UIButton extension to set the color of its background, supporting dynamic colors introduced in iOS 13.
//
// Created by Dongkyu Kim on 2020/01/15.
// Copyright © 2020 Dongkyu Kim. All rights reserved.
//
import UIKit
import UIKit
extension UIView {
func layerImage() -> UIImage {
let renderer = UIGraphicsImageRenderer(bounds: bounds)
let image = renderer.image { context in
layer.render(in: context.cgContext)
}
return image
}
import Foundation
extension URLComponents {
var fragmentItems: [URLQueryItem]? {
get {
var components = URLComponents()
components.query = fragment
return components.queryItems
}
set {
import UIKit
extension UIImage {
func resizeCanvas(size canvasSize: CGSize, color canvasColor: UIColor = .clear) -> UIImage {
let renderer = UIGraphicsImageRenderer(size: canvasSize)
let resizedImage = renderer.image { (context) in
canvasColor.setFill()
context.fill(CGRect(origin: .zero, size: canvasSize))
Array.prototype.replace = function(replacingArray, startIndex = 0) {
const replacedArray = this.slice()
Array.prototype.splice.apply(replacedArray, [startIndex, replacingArray.length].concat(replacingArray))
return replacedArray
}