Skip to content

Instantly share code, notes, and snippets.

View Sorix's full-sized avatar

Vasily Ulianov Sorix

View GitHub Profile
@Sorix
Sorix / UIColor+hex.swift
Created January 27, 2017 13:24
UIColor with hex methods (init from hex, return hex value)
import UIKit
public extension UIColor {
/// Initializes and returns a color object using the specified hex value
///
/// - Parameter hex: hex value, example: `#ffffff` or `ffffff`
public convenience init(hex: String) {
let hexString = hex.trimmingCharacters(in: .whitespacesAndNewlines)
let scanner = Scanner(string: hexString)
@Sorix
Sorix / WebViewWithProgressIndicatorController.swift
Last active April 4, 2024 19:23
NSViewController with WKWebView and progress indicator
//
// WebViewWithProgressIndicatorController
//
// Created by Vasily Ulianov on 29.11.16.
// Copyright © 2016 Vasily Ulianov. All rights reserved.
//
import Cocoa
import WebKit
@Sorix
Sorix / RoundedLabel.swift
Last active July 1, 2022 01:33
IBDesignable UILabel with rounded corners and paddings
import UIKit
@IBDesignable
class RoundedLabel: UILabel {
var edgeInsets: UIEdgeInsets {
if autoPadding {
if cornerRadius == 0 {
return UIEdgeInsets.zero
} else {
@Sorix
Sorix / KeyboardRelatedConstraintAnimator.swift
Last active January 11, 2018 22:55
Move view when keyboard appears, changes frame, disappears
import UIKit
/// Animate and modify constraint's constant when keyboard appears, changes frames or disappears.
/// Use-case: move content above keyboard when it appears.
class KeyboardRelatedConstraintAnimator {
unowned let constraint: NSLayoutConstraint
unowned let view: UIView
private var defaultValue: CGFloat
@Sorix
Sorix / UIView+round.swift
Created August 24, 2016 18:39
Round specified corners of UIView
// Example: view.round([.TopLeft, .TopRight], radius: 15)
extension UIView {
/**
Rounds the given set of corners to the specified radius
- parameter corners: Corners to round
- parameter radius: Radius to round to
*/
func round(corners: UIRectCorner, radius: CGFloat) {
@Sorix
Sorix / FetchedResultsDataSource.swift
Last active September 8, 2022 12:29
UITableViewDataSource boilerplate with NSFetchedResultsController
import UIKit
import CoreData
public protocol FetchedResultsDelegate {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: AnyObject) -> UITableViewCell
}
public class FetchedResultsDataSource: NSObject, UITableViewDataSource, NSFetchedResultsControllerDelegate {
public weak var tableView: UITableView?