Skip to content

Instantly share code, notes, and snippets.

View NikhilManapure's full-sized avatar
🎯
Focusing

Nikhil Manapure NikhilManapure

🎯
Focusing
View GitHub Profile
<key>UIAppFonts</key>
<array>
<string>Nemo Nightmares.ttf</string>
</array>
@NikhilManapure
NikhilManapure / Gif.swift
Last active October 29, 2023 07:31
Create Gif from array of UIImages in Swift 3
import Foundation
import UIKit
import ImageIO
import MobileCoreServices
extension UIImage {
static func animatedGif(from images: [UIImage]) {
let fileProperties: CFDictionary = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]] as CFDictionary
let frameProperties: CFDictionary = [kCGImagePropertyGIFDictionary as String: [(kCGImagePropertyGIFDelayTime as String): 1.0]] as CFDictionary
@NikhilManapure
NikhilManapure / Overlay.swift
Last active May 7, 2021 04:28
Extension of UIImage to give overlay to an image.
extension UIImage {
func overlayed(with overlay: UIImage) -> UIImage? {
defer {
UIGraphicsEndImageContext()
}
UIGraphicsBeginImageContextWithOptions(size, false, scale)
self.draw(in: CGRect(origin: .zero, size: size))
overlay.draw(in: CGRect(origin: .zero, size: size))
if let image = UIGraphicsGetImageFromCurrentImageContext() {
return image
import TOCropViewController
extension EditViewController : TOCropViewControllerDelegate {
func openCrop(image: UIImage) {
let crop = TOCropViewController(image: image)
crop.delegate = self
present(crop, animated: true, completion: nil)
}
extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func presentImagePicker(allowingEditing: Bool) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary){
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary;
imagePickerController.allowsEditing = allowingEditing
self.present(imagePickerController, animated: true, completion: nil)
}
extension AVCaptureDevice {
var hdrMode: HDRMode {
set(newValue){
switch newValue {
case .on:
automaticallyAdjustsVideoHDREnabled = false
isVideoHDREnabled = true
case .off:
automaticallyAdjustsVideoHDREnabled = false
isVideoHDREnabled = false
let motionManager = CMMotionManager() // Class variable, otherwise ARC will delete the object
if motionManager.isGyroAvailable {
if !motionManager.isGyroActive {
motionManager.gyroUpdateInterval = 1.0 / 2.0
motionManager.startGyroUpdates(to: .main, withHandler: { (gyroData, error) in
if let gyroData = gyroData {
print(String(format: "%.02f %.02f %.02f", gyroData.rotationRate.x, gyroData.rotationRate.y, gyroData.rotationRate.z))
} else if let error = error {
print("1Error \(error.localizedDescription)")
class SpinView: UIView {
private var animating: Bool = false
private func spin(with options: UIViewAnimationOptions) {
// this spin completes 360 degrees every 2 seconds
UIView.animate(withDuration: 0.5, delay: 0, options: options, animations: {() -> Void in
self.transform = self.transform.rotated(by: .pi / 2)
}, completion: {(_ finished: Bool) -> Void in
if finished {
if self.animating {
@IBDesignable class GridView: UIView {
var numberOfColumns: Int = 2
var numberOfRows: Int = 2
var lineWidth: CGFloat = 1.0
var lineColor: UIColor = UIColor.white
override func draw(_ rect: CGRect) {
if let context = UIGraphicsGetCurrentContext() {
// HDR
@IBOutlet weak var hdrButton: HDRButton!
var currentHDRMode: HDRMode = .auto
@IBAction func HDRButtonTouched(_ sender: HDRButton) {
toggleHDR()
sender.mode = currentHDRMode
}