Skip to content

Instantly share code, notes, and snippets.

View mukhortov's full-sized avatar
:octocat:

Peter Mukhortov mukhortov

:octocat:
View GitHub Profile
@mukhortov
mukhortov / GetSnapshot+UIView.swift
Created February 28, 2018 08:08
GetSnapshot UIView Extension
//
// GetSnapshot+UIView.swift
//
extension UIView {
func getSnapshot() -> UIView? {
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
// make an image from the pressed tableview cell
@mukhortov
mukhortov / Strikethrough+UILabel.swift
Created February 28, 2018 08:05
Strikethrough UILabel Extension
//
// Strikethrough+UILabel.swift
//
extension UILabel {
func strikethrough() {
if let string = self.text {
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: string)
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 1, range: NSMakeRange(0, attributeString.length))
@mukhortov
mukhortov / UIImageExtensions.swift
Created February 28, 2018 08:04
UIImage Extensions: resize image, grayscale image
//
// UIImageExtensions.swift
//
import CoreImage
extension UIImage {
func resizeImage(width: CGFloat, height: CGFloat) -> UIImage {
UIGraphicsBeginImageContext(CGSize(width: width, height: height))
@mukhortov
mukhortov / UIColorExtensions.swift
Created February 28, 2018 08:02
UIColor Extensions: Hex color, darkened and lightened color
//
// UIColorExtensions.swift
//
import Foundation
extension UIColor {
// creates a color from a hex code example UIColor(hex: 0xFF0000) -> red
convenience init(hex: Int) {
@mukhortov
mukhortov / Tint+UIImageView.swift
Created February 28, 2018 08:00
Tint UIImageView Extension
// Tint+UIImageView.swift
extension UIImageView {
var tint: UIColor {
set {
self.image = self.image!.withRenderingMode(UIImageRenderingMode.alwaysTemplate)
self.tintColor = newValue
}
get {
@mukhortov
mukhortov / CustomView.swift
Created February 28, 2018 07:56
Custom Reusable View Abstract Class
//
// CustomView.swift
//
import UIKit
extension UIView {
// MARK: - Nib loading
public func loadNib() -> UIView {
@mukhortov
mukhortov / UIView+backgroundImage.swift
Last active April 12, 2021 20:26
Add background image to UIView
import UIKit
extension UIView {
func backgroundImage(named: String) {
let backgroundImage = UIImageView(frame: self.frame)
backgroundImage.image = UIImage(named: named)
backgroundImage.contentMode = .scaleAspectFill
backgroundImage.translatesAutoresizingMaskIntoConstraints = false
backgroundImage.center = self.center
backgroundImage.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin]
@mukhortov
mukhortov / TextFieldMacAddress.swift
Last active November 1, 2015 15:57
MAC address text field formatter for UITextField
//
// TextFieldMacAddress.swift
//
// Created by Peter Mukhortov on 01/11/2015.
// Copyright © 2015 Peter Mukhortov. All rights reserved.
//
// MAC address text field formatter for UITextField
//
import Foundation
@mukhortov
mukhortov / ImageTint.swift
Last active August 29, 2015 14:25
UIImageVIew tint extension
extension UIImageView {
var tint: UIColor {
set {
self.image = self.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
self.tintColor = newValue
}
get {
return self.tint
}
}
@mukhortov
mukhortov / UIViewVisibilityToggler.swift
Created May 21, 2015 14:21
UIView show / hide extension (Swift)
extension UIView {
func hide() {
for constraint in self.constraints() as! [NSLayoutConstraint] {
if constraint.firstAttribute == NSLayoutAttribute.Height {
constraint.constant = 0
}
}
}
func show() {