Skip to content

Instantly share code, notes, and snippets.

@MaximAlien
MaximAlien / ViewControllerPresentation
Created December 21, 2015 16:00
[iOS] Change corner radius and size of the UIViewController presented modally
// For UIViewController inside UINavigationController
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.navigationController.view.superview.bounds = CGRectMake(0, 0, 300, 300);
self.navigationController.view.superview.layer.cornerRadius = 2.0f;
}
// Usual presentation
@drosenstark
drosenstark / Donut.swift
Last active April 6, 2019 11:59
(thanks to Paintcode) Draw a hollow circle in swift, or just a piece of one... angle starts at bottom and rotates around clockwise.
class func drawHollowCircle(circleColor: UIColor, rect: CGRect, startAngle: CGFloat = 1, endAngle: CGFloat = 360, outerRingProportion: CGFloat = 1, innerRingProportion: CGFloat = 0.5, drawShadow : Bool) {
//// Variable Declarations
let startAngleCalced: CGFloat = -startAngle + 270
let endAngleCalced: CGFloat = -endAngle + 270
let innerRingDiameter: CGFloat = rect.size.width * innerRingProportion
let innerRingOffset: CGFloat = 0.5 * (rect.size.width - innerRingDiameter)
let innerRingRect = CGRectMake(innerRingOffset, innerRingOffset, innerRingDiameter, innerRingDiameter)
let outerRingDiameter: CGFloat = rect.size.width * outerRingProportion
let outerRingOffset: CGFloat = 0.5 * (rect.size.width - outerRingDiameter)
@aldo-jlaurenstin
aldo-jlaurenstin / MakeTransparentHoleOnOverlayView.swift
Last active May 27, 2024 12:09
Make a Transparent Hole on an Overlay UIView
//
// MakeTransparentHoleOnOverlayView.swift
//
// Created by James Laurenstin on 2015-04-10.
// Copyright (c) 2015 Aldo Group Inc. All rights reserved.
//
import UIKit
class MakeTransparentHoleOnOverlayView: UIView {
@marchinram
marchinram / UIImage+PixelColor.swift
Last active January 19, 2022 08:53
iOS Swift UIImage subscript extension to get pixel color
import UIKit
extension UIImage {
subscript (x: Int, y: Int) -> UIColor? {
guard x >= 0 && x < Int(size.width) && y >= 0 && y < Int(size.height),
let cgImage = cgImage,
let provider = cgImage.dataProvider,
let providerData = provider.data,
let data = CFDataGetBytePtr(providerData) else {
return nil
@willyg302
willyg302 / .lambda.yml
Last active August 11, 2023 06:39
A Lambda function for AES encryption/decryption, from a Gist!
config:
FunctionName: aws-lambda-aes-gist
Handler: index.handler
Runtime: nodejs
Description: A Lambda function for AES encryption/decryption, from a Gist!
install: npm install --production
@macu
macu / timeout.swift
Last active February 22, 2022 08:03
Timeout utility in Swift, with the ability to cancel a deferred callback.
import Foundation
/// Timeout wrapps a callback deferral that may be cancelled.
///
/// Usage:
/// Timeout(1.0) { println("1 second has passed.") }
///
class Timeout: NSObject
{
private var timer: NSTimer?
@shexbeer
shexbeer / gist:cb069d36ca8ec5edb515
Last active August 31, 2018 17:00
Crops a Picture from AVCaptureSession to the bounds of the AVCaptureVideoPreviewLayer (so Preview = CameraImage)
-(UIImage*) cropCameraImage:(UIImage*) original toPreviewLayerBounds:(AVCaptureVideoPreviewLayer*) previewLayer {
UIImage *ret = nil;
CGRect previewImageLayerBounds = previewLayer.bounds;
// This calculates the crop area.
// keeping in mind that this works with on an unrotated image (so a portrait image is actually rotated counterclockwise)
// thats why we use originalHeight to calculate the width
float originalWidth = original.size.width;
float originalHeight = original.size.height;
@ddrccw
ddrccw / hello.h
Created January 14, 2014 04:03
detect jailbreak
//
// Created by ddrccw on 14-1-10.
// Copyright (c) 2014年 ddrccw. All rights reserved.
// refer to http://danqingdani.blog.163.com/blog/static/1860941952012102122847478/
#import <sys/stat.h>
#import <mach-o/dyld.h>
//#import <stdlib.h>
//#import <string.h>
@wess
wess / gist:5161817
Last active December 13, 2019 17:33
Getting visible range of text for a UITextView
@implementation UITextView (Annex)
@dynamic visibleTextRange;
- (NSRange)visibleTextRange
{
CGRect bounds = self.bounds;
CGSize textSize = [self.text sizeWithFont:self.font constrainedToSize:bounds.size];
UITextPosition *start = [self characterRangeAtPoint:bounds.origin].start;
@akshay1188
akshay1188 / whatsapp-image-compression
Last active June 10, 2023 16:42
Whatsapp like image compression
- (UIImage *)compressImage:(UIImage *)image{
float actualHeight = image.size.height;
float actualWidth = image.size.width;
float maxHeight = 600.0;
float maxWidth = 800.0;
float imgRatio = actualWidth/actualHeight;
float maxRatio = maxWidth/maxHeight;
float compressionQuality = 0.5;//50 percent compression
if (actualHeight > maxHeight || actualWidth > maxWidth) {