This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// Usage "String".localize will search for "String" key in Localizeble | |
// Works for all types that conform CustomStringConvertible protocol, e.g. Int, Float. | |
// Raw value will be converted to string and used as key, e.g. | |
// 10.localize, will search for "10" key. | |
// If key not exists, then string value will be returned | |
// Gist: https://gist.github.com/alsedi/357c99ff6d138cf94804 | |
extension CustomStringConvertible { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swift 2.0 port of Objective-C code: http://www.theappguruz.com/blog/onoff-flashlight-one-button-ios | |
// Usage: AVCaptureDevice.turnLight() | |
// It does not work simultaneously with system turn of the torch | |
import AVFoundation | |
extension AVCaptureDevice { | |
static func turnLight() { | |
let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) | |
if ( device.isTorchModeSupported(AVCaptureTorchMode.On) && device.isTorchModeSupported(AVCaptureTorchMode.Off)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Wrapper.swift | |
// Wrap Swift structure into the class. Useful in some operations with NSFoundation classes, | |
// e.g. NSNotificationCenter.postNotificationName | |
// Gist: https://gist.github.com/alsedi/6c8f5f0e313ea490aa69 | |
class Wrapper<T> { | |
private var value: T | |
init(_ value: T) { self.value = value } | |
func unwrap() -> T { return self.value } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
extension UIColor { | |
static func RGBA(r:Int, _ g: Int, _ b:Int, _ a:Int) -> UIColor { | |
return UIColor(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: CGFloat(a)/100.0) | |
} | |
static func RGB(r:Int, _ g: Int, _ b:Int) -> UIColor { | |
return UIColor.RGBA(r, g, b, 100) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+Contstraints.swift | |
// | |
// HOW TO USE | |
// 1. Setup constraints and define NSLayoutConstraint.identifier | |
// 2. Use identifier as parameter for call | |
// 3. Call on superview: if let constraint = self.view.constraintByStringId("Id") { } | |
// 4. Change, animate or replace constraint | |
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func animate() { | |
if shapes.count == 0 { | |
generateShapes() | |
} | |
// Animation | |
} | |
private func generateShapes() { | |
// Generate shapes todo | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var shapes = [MutableShapeLayer]() | |
private let minimalSize = CGSize(width: 50, height: 50) | |
var step: CGFloat = 55.0 | |
var shapeWidth: CGFloat = 20 | |
var shapesCount:Int = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var circlePath: CGPath { | |
let circle = UIBezierPath(ovalIn: CGRect(origin: CGPoint.zero, size: frame.size)) | |
circle.close() | |
// 1 | |
return circle.cgPath | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var rectanglePath: CGPath { | |
let width = frame.size.width | |
let height = frame.size.height | |
let myPath = UIBezierPath() | |
myPath.lineCapStyle = CGLineCap.butt | |
myPath.lineJoinStyle = CGLineJoin.miter | |
myPath.move(to: CGPoint.zero) | |
myPath.addQuadCurve(to: CGPoint(x:width,y:0), controlPoint:CGPoint(x:width/2.0,y:0)) | |
myPath.addQuadCurve(to: CGPoint(x:width,y:height), controlPoint:CGPoint(x:width,y:height/2.0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setup(size:CGSize, center:CGPoint, thickness: CGFloat) { | |
frame = CGRect(origin: CGPoint.zero, size: size) | |
position = center | |
path = circlePath | |
lineWidth = thickness | |
strokeColor = UIColor.black.cgColor | |
fillColor = UIColor.clear.cgColor | |
} |
OlderNewer