This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BonjourClient.swift | |
// BonjourClient | |
// | |
// Created by Jesse Hao on 2019/5/23. | |
// Copyright © 2019 ONES. All rights reserved. | |
// | |
import Foundation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FreedrawingImageViewCG: UIImageView { | |
var currentTouchPosition: CGPoint? | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
isUserInteractionEnabled = true | |
} | |
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by はるふ on 2017/12/11. | |
// Copyright © 2017年 ha1f. All rights reserved. | |
// | |
import Foundation | |
import CoreImage | |
import AVFoundation | |
extension CIFilter { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |