Skip to content

Instantly share code, notes, and snippets.

View AnnieNinaJoyceV's full-sized avatar

Joycey ✌️ AnnieNinaJoyceV

View GitHub Profile
@MaherKSantina
MaherKSantina / UIView+Embed.swift
Last active October 22, 2019 06:18
This gist helps with placing views inside each other using autolayout constraints
public typealias ConstraintsConfiguration = (_ top: NSLayoutConstraint, _ left: NSLayoutConstraint, _ bottom: NSLayoutConstraint, _ right: NSLayoutConstraint) -> Void
extension UIView {
/**
Embeds a subview inside the current view and adds constraints to fit the subview in the whole view. An optional constraints configuration closure can be specified to do extra customization for the added constraints, or you can keep a reference for the added constraints in this closure.
- Parameter subview: The subview that will be added
- Parameter constraintsConfiguration: The constraint configuration that will be applied to the newly added constraints
*/
public func addSubviewWithConstraints(_ subview: UIView, constraintsConfiguration: ConstraintsConfiguration? = nil) {
// Required to disable auto generation of constraints
@JoeFerrucci
JoeFerrucci / CopyableLabel.swift
Created May 20, 2016 17:04
CopyableLabel - a typical UILabel with "Copy" functionality.
import UIKit
class CopyableLabel: UILabel {
override init(frame: CGRect) {
super.init(frame: frame)
userInteractionEnabled = true
addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(CopyableLabel.showMenu(_:))))
}
@ashishkakkad8
ashishkakkad8 / AFWrapper.swift
Last active January 13, 2020 07:08
Alamofire - SwiftyJSON Wrapper
//
// AFWrapper.swift
// AFSwiftDemo
//
// Created by Ashish on 10/4/16.
// Copyright © 2016 Ashish Kakkad. All rights reserved.
//
import UIKit
import Alamofire
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@nvkiet
nvkiet / [Swift] Switch-RootViewController
Last active June 21, 2023 12:35
Switch root view controller
func switchRootViewController(rootViewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
if animated {
UIView.transitionWithView(window, duration: 0.5, options: .TransitionCrossDissolve, animations: {
let oldState: Bool = UIView.areAnimationsEnabled()
UIView.setAnimationsEnabled(false)
self.window!.rootViewController = rootViewController
UIView.setAnimationsEnabled(oldState)
}, completion: { (finished: Bool) -> () in
if completion {
completion!()
@ijoshsmith
ijoshsmith / CrossJoin.swift
Last active January 2, 2019 22:59
Cross-joining two Swift arrays
extension Array
{
func crossJoin<E, R>(
array: [E],
joiner: (t: T, e: E) -> R?)
-> [R]
{
return arrayCrossJoin(self, array, joiner)
}
}
@rabovik
rabovik / UIImage+RSSaveToDesktop.h
Last active December 25, 2015 00:59
Save UIImage to Desktop on iOS Simulator
#if TARGET_IPHONE_SIMULATOR
@interface UIImage (RSSaveToDesktop)
/// Creates a RSUIImage directory on desktop and saves image to it.
-(void)rs_saveToDesktop;
/// Creates a RSUIImage directory on desktop and saves image to it with specified name.
-(void)rs_saveToDesktopWithName:(NSString *)customName;