Skip to content

Instantly share code, notes, and snippets.

@gkye
gkye / shiftArrayIndex.swift
Created February 22, 2016 03:58
shift array index
mutating func moveItem(fromIndex oldIndex: Index, toIndex newIndex: Index) {
insert(removeAtIndex(oldIndex), atIndex: newIndex)
}
var tags = [1,2,3,4,5,7782,25]
tags.moveItem(fromIndex: 2, toIndex: tags.count-1)
@gkye
gkye / shuffleArray.swift
Last active February 22, 2016 03:59
shuffle array (self)
mutating func shuffle() {
if count < 2 { return }
for i in 0..<(count - 1) {
let j = Int(arc4random_uniform(UInt32(count - i))) + i
swap(&self[i], &self[j])
}
}
var tags = [1,7782,25]
tags.shuffle()
class VerticalLayout: UIView {
var yOffsets: [CGFloat] = []
init(width: CGFloat) {
super.init(frame: CGRectMake(0, 0, width, 0))
}
required init(coder aDecoder: NSCoder) {
@gkye
gkye / clear cache memory warning
Created March 24, 2016 17:34
clear cache memory warning. swift 2.2
func applicationDidReceiveMemoryWarning(application: UIApplication) {
NSURLCache.sharedURLCache().removeAllCachedResponses()
}
--http://stackoverflow.com/a/26326006/5222077
public extension UIView {
public class func fromNib(nibNameOrNil: String? = nil) -> Self {
return fromNib(nibNameOrNil, type: self)
}
public class func fromNib<T : UIView>(nibNameOrNil: String? = nil, type: T.Type) -> T {
let v: T? = fromNib(nibNameOrNil, type: T.self)
return v!
extension String {
//Convert html strings to an attributed string
var html2AttributedString: NSMutableAttributedString? {
guard
let data = dataUsingEncoding(NSUTF8StringEncoding)
else { return nil }
do {
let attrStr = try NSMutableAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute:NSUTF8StringEncoding], documentAttributes: nil)
attrStr.addAttributes([NSFontAttributeName: UIFont.systemFontOfSize(17.0)], range: NSRange(location: 0, length: attrStr.length))
return attrStr

Swiper

UIView sublass for creating Tinder like swipe cards, with a peek view.

Usage

Check out the demo app for a detailed example.

Adding Swiper View

A Swiper view can be added via storyboard or programmatically

var swiperView = Swiper(frame: CGRect(x: 0, y: 0, width: 350, height: 350)))

Updates

  • Added public func pauseInteractiveTransition() to ContainerTransition
  • Updated Project Settings,
  • Updated inout parameters
  • Guard stament to prevent presentingViewController from returning nil and crashing (Flip presentation)
  • Issues Unable to go back after using Cover presentation
@gkye
gkye / UIImage+PixelColor.swift
Created August 20, 2016 23:42 — forked from marchinram/UIImage+PixelColor.swift
iOS Swift UIImage subscript extension to get pixel color
import UIKit
extension UIImage {
subscript (x: Int, y: Int) -> UIColor? {
if x < 0 || x > Int(size.width) || y < 0 || y > Int(size.height) {
return nil
}
let darkNavy = UIColor(red:0.07, green:0.09, blue:0.18, alpha:1.0)
let lightBlue = UIColor(red:0.22, green:0.52, blue:0.84, alpha:1.0)
let oceanGreen = UIColor(red:0.22, green:0.52, blue:0.84, alpha:1.0)
let lightningYellow = UIColor(red:0.98, green:0.71, blue:0.16, alpha:1.0)
let greyBlue =UIColor(red:0.55, green:0.56, blue:0.63, alpha:1.0)
let geenishGrey = UIColor(red:0.80, green:0.85, blue:0.75, alpha:1.0)
let lighterBlue = UIColor(red:0.53, green:0.67, blue:0.86, alpha:1.0)
let mustardYellow = UIColor(red:0.83, green:0.63, blue:0.23, alpha:1.0)