Skip to content

Instantly share code, notes, and snippets.

Michał Mosiołek swifted

Block or report user

Report or block swifted

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@swifted
swifted / QuadPageControl.swift
Last active Apr 23, 2020
UIPageControl with square dots having custom size (hack).
View QuadPageControl.swift
import UIKit
class QuadPageControl: UIPageControl {
override func layoutSubviews() {
super.layoutSubviews()
guard !subviews.isEmpty else { return }
let spacing: CGFloat = 3
View UIImage+Snapshot.swift
import UIKit
extension UIImage {
static func imageFromView(view: UIView) -> UIImage {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0)
view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
@swifted
swifted / UIImage+Placeholder.swift
Created Aug 22, 2016
Shorthand for creating empty (black) UIImage.
View UIImage+Placeholder.swift
import UIKit
extension UIImage {
static func placeholder(size: CGSize) -> UIImage {
UIGraphicsBeginImageContext(size)
let context = UIGraphicsGetCurrentContext()
CGContextSetRGBFillColor(context, 0, 0, 0, 1)
CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height))
@swifted
swifted / CustomURLCache.swift
Created Aug 22, 2016
Custom NSURLCache for web services which don't provide expiration info.
View CustomURLCache.swift
import Foundation
class CustomURLCache: NSURLCache {
let createdAtKey = "CreatedAt"
override func cachedResponseForRequest(request:NSURLRequest) -> NSCachedURLResponse? {
let cachedResponse = expiredCachedResponseForRequest(request)
if cachedResponse == nil {
@swifted
swifted / String+Titleized.swift
Created Aug 22, 2016
String with the first letter written uppercase.
View String+Titleized.swift
import Foundation
extension String {
var titleizedString: String {
return String(characters.prefix(1)).uppercaseString + String(characters.dropFirst())
}
}
@swifted
swifted / UIViewController+Alert.swift
Last active Aug 31, 2016
Present basic alert with UIViewController.
View UIViewController+Alert.swift
import UIKit
extension UIViewController {
func presentAlert(message: String) {
if presentedViewController == nil {
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .Alert)
let alertAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(alertAction)
@swifted
swifted / SKNodeExtension.swift
Last active Aug 22, 2016
Remove SKNode children whose names match the search parameter.
View SKNodeExtension.swift
import SpriteKit
extension SKNode {
public func removeChildrenWithName(name: String) {
enumerateChildNodesWithName(name) { (node, stop) -> Void in
node.removeFromParent()
}
}
}
@swifted
swifted / CoreGraphics+Geometry.swift
Last active Jun 19, 2018
Convert degrees to radians / radians to degrees in Swift.
View CoreGraphics+Geometry.swift
import CoreGraphics
func degreesToRadians(degrees: CGFloat) -> CGFloat {
return degrees * CGFloat(M_PI) / 180
}
func radiansToDegress(radians: CGFloat) -> CGFloat {
return radians * 180 / CGFloat(M_PI)
}
View CGSizeExtension.swift
import CoreGraphics
extension CGSize {
public init(side: CGFloat) {
width = side
height = side
}
public init(side: Double) {
width = CGFloat(side)
You can’t perform that action at this time.