Skip to content

Instantly share code, notes, and snippets.

@gbarcena
gbarcena / UIBezierPath+SVGString.swift
Created October 25, 2018 18:27
Get SVG from UIBezierPath
// Converted from: https://github.com/GenerallyHelpfulSoftware/SVGgh/blob/master/SVGgh/SVGRenderer/SVGPathGenerator.m#L1873
extension UIBezierPath {
var svgPathString: String {
var finalString = ""
let cgPath = self.cgPath
var currentPoint = CGPoint.zero
cgPath.applyWithBlock { (aPathElement) in
switch aPathElement.pointee.type {
case .moveToPoint:
currentPoint = aPathElement.pointee.points[0]
@gbarcena
gbarcena / video_transform.swift
Created July 7, 2017 19:21
Correcting the transform on a video for AVExportSession
let preferredTransform = originalVideoTrack.preferredTransform
let finalTransform: CGAffineTransform
// These if statements were added to handle time lapse videos which use abcd for transforms
// and not tx, ty
if preferredTransform.a == -1 && preferredTransform.d == -1 {
transform = transform.scaledBy(x: -1, y: -1)
finalTransform = transform.translatedBy(x: -outputVideoSize.width, y: -outputVideoSize.height)
} else if preferredTransform.b == 1 && preferredTransform.c == -1 {
transform = transform.rotated(by: CGFloat.pi/2)
finalTransform = transform.translatedBy(x: 0, y: -outputVideoSize.width)
@gbarcena
gbarcena / gist:e5e6ad3668bccc240a68
Last active August 29, 2015 14:05
Rounding Image Corners
-(void)setupButton:(UIButton *)button bounds:(CGRect)bounds cornerRadius:(CGFloat)cornerRadius bgColor:(UIColor *)bgColor
{
UIImage *image = [[self class] imageWithFrame:bounds
cornerRadius:cornerRadius
roundingCorners:UIRectCornerBottomLeft
bgColor:bgColor];
[button setBackgroundImage:image forState:UIControlStateNormal];
button.backgroundColor = [UIColor clearColor];
[button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
}
@gbarcena
gbarcena / ApplyBorderColorToImage
Last active August 29, 2015 13:59
Adds a masked colored border to an image
- (UIImage *)applyBorderColor:(UIColor *)color toImage:(UIImage*)toImage{
UIGraphicsBeginImageContextWithOptions(toImage.size, NO, toImage.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, toImage.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGRect rect = CGRectMake(0, 0, toImage.size.width, toImage.size.height);
// Create gradient