Skip to content

Instantly share code, notes, and snippets.

View maximbilan's full-sized avatar
🧑‍🚒
Working...

Maksym Bilan maximbilan

🧑‍🚒
Working...
View GitHub Profile
import Foundation
public extension UIColor {
class func StringFromUIColor(color: UIColor) -> String {
let components = CGColorGetComponents(color.CGColor)
return "[\(components[0]), \(components[1]), \(components[2]), \(components[3])]"
}
class func UIColorFromString(string: String) -> UIColor {
import Foundation
import UIKit
@objc public class LeftAlignedSearchBar: UISearchBar, UISearchBarDelegate {
override public var placeholder:String? {
didSet {
if #available(iOS 9.0, *) {
if let text = placeholder {
if text.characters.last! != " " {
let attr = UITextField.appearanceWhenContainedInInstancesOfClasses([LeftAlignedSearchBar.self]).defaultTextAttributes
@maximbilan
maximbilan / tvOSCustomButtonHighlighting.swift
Last active October 30, 2015 18:48
tvOS Custom Button Highlighting
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
context.nextFocusedView!.layer.shadowOffset = CGSizeMake(0, 15)
context.nextFocusedView!.layer.shadowOpacity = 0.6
context.nextFocusedView!.layer.shadowRadius = 50
context.nextFocusedView!.layer.shadowColor = UIColor.redColor().CGColor
context.previouslyFocusedView?.layer.shadowOpacity = 0
}
@maximbilan
maximbilan / AppDelegate.swift
Created October 21, 2015 17:34
Mac OS X Application Popup App Delegate
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-2)
let popover = NSPopover()
var eventMonitor: EventMonitor?
func applicationDidFinishLaunching(aNotification: NSNotification) {
@maximbilan
maximbilan / EventMonitor.swift
Created October 21, 2015 17:29
Mac OS X Event Monitor
import Cocoa
public class EventMonitor {
private var monitor: AnyObject?
private let mask: NSEventMask
private let handler: NSEvent? -> ()
public init(mask: NSEventMask, handler: NSEvent? -> ()) {
self.mask = mask
@maximbilan
maximbilan / YouTubeParseLinks.m
Last active October 20, 2015 13:02
YouTubeParseLinks.m
@maximbilan
maximbilan / YouTubeParseLinks.swift
Created October 20, 2015 12:59
YouTubeParseLinks.swift
@maximbilan
maximbilan / CoreDataStorage.swift
Created October 18, 2015 15:49
Core Data Storage
//
// CoreDataStorage.swift
// TutorialAppGroup
//
// Created by Maxim on 10/18/15.
// Copyright © 2015 Maxim. All rights reserved.
//
import Foundation
import CoreData
private var propertyAssociationKey: UInt8 = 0
extension String {
weak var property: CustomClass! {
get {
return objc_getAssociatedObject(self, &propertyAssociationKey) as? CustomClass
}
set(newValue) {
objc_setAssociatedObject(self, &propertyAssociationKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
@maximbilan
maximbilan / ArrayShuffle.swift
Last active September 15, 2015 15:43
Swift Array Shuffle
import Foundation
extension CollectionType where Index == Int {
func shuffle() -> [Generator.Element] {
var list = Array(self)
list.shuffleInPlace()
return list
}
}