Skip to content

Instantly share code, notes, and snippets.

View sohilmemon's full-sized avatar
🎯
Focusing

sohilmemon

🎯
Focusing
View GitHub Profile
@PetreVane
PetreVane / CAShapeLayer Shapes.swift
Created April 1, 2020 09:25
Creates rectangles, triangles and ovals
extension CAShapeLayer {
static func rectangle(roundedRect: CGRect, cornorRadius: CGFloat, color: UIColor) -> CAShapeLayer {
let path = UIBezierPath(roundedRect: roundedRect, cornerRadius: cornorRadius)
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.fillColor = color.cgColor
return shape
}
}
@jessehao
jessehao / BonjourClient.swift
Created May 23, 2019 09:06
A simple example for Bonjour
//
// BonjourClient.swift
// BonjourClient
//
// Created by Jesse Hao on 2019/5/23.
// Copyright © 2019 ONES. All rights reserved.
//
import Foundation
@almaleh
almaleh / SlowCPU-based.swift
Last active July 16, 2023 05:45
Slow CPU-based Drawing
class FreedrawingImageViewCG: UIImageView {
var currentTouchPosition: CGPoint?
override func layoutSubviews() {
super.layoutSubviews()
isUserInteractionEnabled = true
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
@StanDimitroff
StanDimitroff / UIImage+Clipp.swift
Last active April 25, 2024 04:52
Image clipping to UIBezierPath
extension UIImage {
func imageByApplyingClippingBezierPath(_ path: UIBezierPath) -> UIImage {
// Mask image using path
guard let let maskedImage = imageByApplyingMaskingBezierPath(path) else { return nil }
// Crop image to frame of path
let croppedImage = UIImage(cgImage: maskedImage.cgImage!.cropping(to: path.bounds)!)
return croppedImage
}
@ha1f
ha1f / CIFilter+Extension.swift
Last active February 20, 2024 08:14
CIFilter+Extension.swift
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {
@nyg
nyg / EXIFUserComment.swift
Last active June 6, 2024 19:42
Get and set an EXIF UserComment to a JPEG image using the ImageIO framework.
// Note: to add a JPEG COM marker go here:
// https://gist.github.com/nyg/bdeae8190a41b4b56bde8e13dd471ecc
import Foundation
import ImageIO
#if os(iOS)
import MobileCoreServices
#endif
@norsez
norsez / UIImage+Rotation.swift
Last active February 19, 2023 04:54
Rotate UIImage by radians in Swift 3
extension UIImage {
func image(withRotation radians: CGFloat) -> UIImage {
let cgImage = self.cgImage!
let LARGEST_SIZE = CGFloat(max(self.size.width, self.size.height))
let context = CGContext.init(data: nil, width:Int(LARGEST_SIZE), height:Int(LARGEST_SIZE), bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: 0, space: cgImage.colorSpace!, bitmapInfo: cgImage.bitmapInfo.rawValue)!
var drawRect = CGRect.zero
drawRect.size = self.size
let drawOrigin = CGPoint(x: (LARGEST_SIZE - self.size.width) * 0.5,y: (LARGEST_SIZE - self.size.height) * 0.5)
@fdstevex
fdstevex / allbonjour.swift
Created May 15, 2016 02:32
Swift command-line script to find Bonjour services on your local network.
#!/usr/bin/swift
// Swift script to search for Bonjour services on the local network.
// Found services are printed to the console.
import Foundation
import CoreFoundation
// Inner search, finds services of a particular type
extension UIImage {
public func imageRotatedByDegrees(degrees: CGFloat) -> UIImage {
let radiansToDegrees: (CGFloat) -> CGFloat = {
return $0 * (180.0 / CGFloat(M_PI))
}
let degreesToRadians: (CGFloat) -> CGFloat = {
return $0 / (180.0 * CGFloat(M_PI))
}
// calculate the size of the rotated view's containing box for our drawing space