Skip to content

Instantly share code, notes, and snippets.

@soggybag
soggybag / CustomView.swift
Created February 17, 2016 05:38
CustomView Class adds designable and inspectable properties for Corner radius, border color, and border width
import UIKit
@IBDesignable
class CustomView: UIView {
@IBInspectable var borderColor: UIColor? = UIColor.clearColor() {
didSet {
layer.borderColor = self.borderColor?.CGColor
}
}
@soggybag
soggybag / DismissSegue.swift
Created February 15, 2016 07:08
DismissSegue - Adds a Dismiss siege to storyboard
import UIKit
@objc(DismissSegue)
class DismissSegue: UIStoryboardSegue {
override func perform() {
if let controller = sourceViewController.presentingViewController {
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
}
@soggybag
soggybag / CustomImageView.swift
Created February 13, 2016 18:26
Adds inspectable designable border and corner radius to UIImageView
import UIKit
@IBDesignable
class CustomImageView: UIImageView {
@IBInspectable var borderColor: UIColor? = UIColor.clearColor() {
didSet {
layer.borderColor = self.borderColor?.CGColor
}
}
@soggybag
soggybag / CustomButton.swift
Created February 9, 2016 21:45
Custom Designable, Inspectable button with border and corner radius.
import UIKit
@IBDesignable
class CustomButton: UIButton {
@IBInspectable var borderColor: UIColor? = UIColor.clearColor() {
didSet {
layer.borderColor = self.borderColor?.CGColor
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
@soggybag
soggybag / Extensions.swift
Created January 18, 2016 18:02
Random Int Extension using Gameplaykit
import GameplayKit
// MARK:
extension Int {
// Make this a static function for Int
static func randomRange(range: Int) -> Int {
return GKRandomSource.sharedRandom().nextIntWithUpperBound(range)
}
}
@soggybag
soggybag / ViewController.swift
Created January 7, 2016 06:15
transitionFromViewController
print("Last Page Said Done")
if let appVC = storyboard?.instantiateViewControllerWithIdentifier("YourAppViewControler") {
let currentVC = pageViewController
appVC.view.frame = currentVC.view.frame
appVC.willMoveToParentViewController(nil)
addChildViewController(appVC)
transitionFromViewController(currentVC, toViewController: appVC, duration: 1.0, options: .TransitionCrossDissolve, animations: { () -> Void in
//
@soggybag
soggybag / ViewController.swift
Created December 25, 2015 07:18
Load data from plist
func loadDataFromPlist(plist: String) -> NSArray? {
if let path = NSBundle.mainBundle().pathForResource(plist, ofType: "plist") {
return NSArray(contentsOfFile: path)
}
return nil
}
@soggybag
soggybag / ViewController.swift
Created December 10, 2015 15:21
Zebra Striped cells
// Somewhere inside cellForRowAtIndexPath
// You could use this to color every other cell
// Use % 2 to find each odd numbered cell
if indexPath.row % 2 == 0 {
cell.backgroundColor = UIColor(hue: 0.43, saturation: 1.0, brightness: 0.75, alpha: 1.0)
} else {
cell.backgroundColor = UIColor(hue: 0.43, saturation: 1.0, brightness: 0.85, alpha: 1.0)
}
@soggybag
soggybag / ViewController.swift
Created December 10, 2015 15:21
Colored Cells, cells changed brightness.
// Somewhere inside of cellForRowAtIndexPath
// Or, set the brightness. Here the min value is 0.55 and max value is 1.0 (0.45 + 0.55)
let b = 0.45 / CGFloat(array.count) * CGFloat(indexPath.row) + 0.55
cell.backgroundColor = UIColor(hue: 0.5, saturation: 1.0, brightness: b, alpha: 1.0)
@soggybag
soggybag / ViewController.swift
Created December 10, 2015 15:19
Rainbow tableview cells
// Somwhere inside of cellForRowAtIndexPath
// Color cells by changing hue
let hue = 1 / CGFloat(array.count) * CGFloat(indexPath.row)
cell.backgroundColor = UIColor(hue: hue, saturation: 1.0, brightness: 1.0, alpha: 1.0)