Skip to content

Instantly share code, notes, and snippets.

View ptvyas's full-sized avatar

Piyush V ptvyas

  • Surat, Gujarat, India
  • 03:26 (UTC +05:30)
View GitHub Profile
/*
File: UIImage+ImageEffects.h
Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur.
Version: 1.0
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
@db0company
db0company / topMostViewController.swift
Created January 19, 2015 14:28
Get the top most viewController anywhere in the app (typically from the appDelegate). Get the current visible viewController.
extension UIViewController {
func topMostViewController() -> UIViewController {
if self.presentedViewController == nil {
return self
}
if let navigation = self.presentedViewController as? UINavigationController {
return navigation.visibleViewController.topMostViewController()
}
if let tab = self.presentedViewController as? UITabBarController {
if let selectedTab = tab.selectedViewController {
@brocoo
brocoo / Extensions.swift
Last active April 12, 2021 13:27
Swift UIImage extension for base64 conversion
// MARK: - UIImage (Base64 Encoding)
public enum ImageFormat {
case PNG
case JPEG(CGFloat)
}
extension UIImage {
public func base64(format: ImageFormat) -> String {
@eleev
eleev / URLForPHAsset.swift
Last active February 17, 2024 23:56
Getting URL for PHAsset (Swift 3.0)
func getURL(ofPhotoWith mPhasset: PHAsset, completionHandler : @escaping ((_ responseURL : URL?) -> Void)) {
if mPhasset.mediaType == .image {
let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions()
options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in
return true
}
mPhasset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in
completionHandler(contentEditingInput!.fullSizeImageURL)
})
//
// StandardTooltip.swift
//
// Created by Albert Bori on 11/20/17.
//
import Foundation
@objc
class StandardTooltip: NSObject {
extension UIImage {
func blurred(radius: CGFloat) -> UIImage {
let ciContext = CIContext(options: nil)
guard let cgImage = cgImage else { return self }
let inputImage = CIImage(cgImage: cgImage)
guard let ciFilter = CIFilter(name: "CIGaussianBlur") else { return self }
ciFilter.setValue(inputImage, forKey: kCIInputImageKey)
ciFilter.setValue(radius, forKey: "inputRadius")
guard let resultImage = ciFilter.value(forKey: kCIOutputImageKey) as? CIImage else { return self }
@mansi-27
mansi-27 / UIView+Extensions
Last active April 30, 2018 07:18
Produce horizontal shake animation
extension UIView {
/// Produce horizontal shake animation
func shakeHorizontally(withCount count: Float = 4, duration: TimeInterval = 0.3, translation: Float = -10) {
let animation: CABasicAnimation = CABasicAnimation(keyPath: "transform.translation.x")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.repeatCount = count
animation.duration = (duration)/TimeInterval(animation.repeatCount)
animation.autoreverses = true
@mansi-27
mansi-27 / UIView+Extensions
Created February 22, 2018 18:00
Sets rounded corners to the UIView
extension UIView {
/// Sets rounded corners to the UIView
func roundedCorners(radius: CGFloat? = nil) {
if let radius = radius {
layer.cornerRadius = radius
} else {
layer.cornerRadius = frame.size.height / 2
}
clipsToBounds = true
@mansi-27
mansi-27 / UIView+Extensions
Created February 22, 2018 18:01
Produce vertical shake animation
extension UIView {
/// Produce vertical shake animation
func shakeVertically(withCount count: Float = 4, duration: TimeInterval = 0.3, translation: Float = -10) {
let animation: CABasicAnimation = CABasicAnimation(keyPath: "transform.translation.y")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.repeatCount = count
animation.duration = (duration)/TimeInterval(animation.repeatCount)
animation.autoreverses = true
@mansi-27
mansi-27 / UIView+Extensions
Created February 22, 2018 18:02
Sets border to the UIView
extension UIView {
/// Sets border to the UIView
func setViewBorder(withWidth width: CGFloat = 1.0, color: UIColor) {
self.layer.borderWidth = width
self.layer.borderColor = color.cgColor
}
}