Skip to content

Instantly share code, notes, and snippets.

View jwilling's full-sized avatar

Jonathan Willing jwilling

View GitHub Profile
@jwilling
jwilling / JWLocationManager.h
Created July 31, 2012 20:02
Block-based wrapper around Core Location
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
typedef void (^JWLocationManagerCallback)(CLLocation *location);
typedef void (^JWLocationManagerErrorCallback)(NSError *error);
@interface JWLocationManager : NSObject <CLLocationManagerDelegate>
@property (nonatomic, copy) NSString *purpose;
@property (nonatomic, copy) JWLocationManagerCallback locationUpdatedBlock;
@jwilling
jwilling / NSView+Animations.m
Created July 4, 2012 22:28
NSView add/removeSubview animated
@implementation NSView (Animations)
- (void)addSubview:(NSView *)aView animated:(BOOL)animated {
[aView setAlphaValue:0.f];
[aView setFrameOrigin:NSZeroPoint];
CGFloat duration = animated ? (([[[self window] currentEvent] modifierFlags] & NSShiftKeyMask) ? 1.f : 0.25f ) : 0.f;
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:duration];
@jwilling
jwilling / gist:2773202
Created May 23, 2012 04:03
Simple category for changing window size to fit content
- (void)resizeWindowForContentSize:(NSSize)size animated:(BOOL)animated {
NSRect windowFrame = [self contentRectForFrameRect:[self frame]];
NSRect newWindowFrame = [self frameRectForContentRect:
NSMakeRect( NSMinX( windowFrame ), NSMaxY( windowFrame ) - size.height, size.width, size.height )];
[self setFrame:newWindowFrame display:YES animate:animated];
}
@jwilling
jwilling / gist:2292277
Created April 3, 2012 14:08
Drawing with shadow offset
- (void)drawInRect:(CGRect)rect {
CGSize shadowOffset = CGSizeMake(0, -1);
float colorValues[] = {0, 0, 0, .9};
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
CGContextSetShadow (ctx, shadowOffset, 1);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef color = CGColorCreate(colorSpace, colorValues);