Skip to content

Instantly share code, notes, and snippets.

View stleamist's full-sized avatar

Dongkyu “Max” Kim stleamist

View GitHub Profile
import UIKit
extension UITableViewCell {
static var reuseIdentifier: String { String(describing: self) }
}
import UIKit
extension UIColor {
static func dynamicColor(light: UIColor, dark: UIColor) -> UIColor {
return UIColor { (traitCollection) -> UIColor in
if traitCollection.userInterfaceStyle != .dark {
return light
} else {
return dark
}
import UIKit
let disclosureIndicatorImage = UIImage(systemName: "chevron.right")?
.applyingSymbolConfiguration(.init(scale: .small))?
.applyingSymbolConfiguration(.init(weight: .semibold))?
.withTintColor(UIColor.systemGray.withAlphaComponent(0.5), renderingMode: .alwaysOriginal)
let disclosureIndicator = UIImageView(image: disclosureIndicatorImage)
const { Canvg, presets } = require('canvg')
const { DOMParser } = require('xmldom')
const canvas = require('canvas')
const fetch = require('node-fetch')
const preset = presets.node({ DOMParser, canvas, fetch })
module.exports = async function svgToCanvas(svg) {
try {
import UIKit
extension UIStoryboard {
static var launchScreen: UIStoryboard? {
guard let launchStoryboardName = Bundle.main.object(forInfoDictionaryKey: "UILaunchStoryboardName") as? String else {
return nil
}
return UIStoryboard(name: launchStoryboardName, bundle: .main)
}
}
import UIKit
class ContainerViewController: UIViewController {
convenience init(contentViewController: UIViewController) {
self.init()
self.contentViewController = contentViewController
}
var contentViewController: UIViewController? {
@stleamist
stleamist / OfferButton.swift
Last active May 19, 2020 11:10
A replication of download button in the App Store.
import UIKit
class OfferButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
@stleamist
stleamist / extractViewsFromContent.swift
Created May 19, 2020 10:36
An experimental way to extract SwiftUI views from an TupleView built by ViewBuilder.
import SwiftUI
func extractViewsFromContent<Content: View> (@ViewBuilder content: () -> Content) -> [Any] {
let tupleView = content()
let tupleViewMirror = Mirror(reflecting: tupleView)
let tuple = tupleViewMirror.children.first!.value
let tupleMirror = Mirror(reflecting: tuple)
let views = tupleMirror.children.map { $0.value }
return views
}
@stleamist
stleamist / PageView.swift
Created May 19, 2020 11:08
A representation of UIPageViewController in SwiftUI.
import SwiftUI
struct PageView<Page: View>: UIViewControllerRepresentable {
var pages: [Page]
@Binding var currentPage: Int
func makeUIViewController(context: Context) -> UIPageViewController {
let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)
@stleamist
stleamist / UnicodeURLDecodingEnabler.swift
Created June 15, 2020 12:24
A KeyedDecodingContainer extension that adds percent encoding to Unicode URL during Codable decoding process.
import Foundation
extension KeyedDecodingContainer {
func decode(_ type: URL.Type, forKey key: Key) throws -> URL {
do {
return try URL(from: superDecoder())
} catch (let error) {
guard
let urlString = try? decode(String.self, forKey: key),