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 / rotate.less
Last active August 29, 2015 14:15 — forked from swider/rotate.less
.rotate(@val) {
-moz-transform: rotate(@val); /* FF3.5+ */
-o-transform: rotate(@val); /* Opera 10.5 */
-webkit-transform: rotate(@val); /* Saf3.1+, Chrome */
-ms-transform: rotate(@val); /* IE9 */
transform: rotate(@val);
/* IE6-IE8 */
@radians: ~`parseInt("@{val}") * Math.PI * 2 / 360`;
@costheta: ~`Math.cos("@{radians}")`;
@mukhortov
mukhortov / UIViewResizeExtension.swift
Created May 21, 2015 14:19
UIView Resize Extension (Swift)
extension UIView {
func resizeX(width: CGFloat) {
for constraint in self.constraints() as! [NSLayoutConstraint] {
if constraint.firstAttribute == NSLayoutAttribute.Width {
constraint.constant = width
}
}
}
func resizeY(height: CGFloat) {
@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() {
@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 / 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 / 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 / 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 / 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 / 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 / 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))