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
/* | |
Copied and pasted from Tim Oliver's blog. | |
Source: http://www.tim-oliver.com/2011/10/23/creating-the-uitableview-bevel-effect-in-coregraphics/ | |
*/ | |
void DrawInsetBeveledRoundedRect(CGContextRef context, CGRect rect, CGFloat radius, UIColor *fillColor) { | |
//contract the bounds of the rectangle in to account for the stroke | |
CGRect drawRect = CGRectInset(rect, 1.0f, 1.0f); | |
//contract the height by 1 to account for the white bevel at the bottom |
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
/* | |
Copied and pasted from David Hamrick's blog. | |
Source: http://www.davidhamrick.com/2011/08/07/using-blocks-for-drawing-to-avoid-subclasssing-in-objective-c.html | |
*/ | |
typedef void(^DrawView_DrawBlock)(UIView* v,CGContextRef context); | |
@interface DrawView : UIView |
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
// via @_bejo | |
// then just add a DEBUG = 1 to debug target in xcode | |
#ifdef DEBUG | |
#define DebugLog( s, ... ) NSLog( @"<%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) | |
#else | |
#define DebugLog( s, ... ) |
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
/* | |
Source: Apple Developer - Understanding iOS View Compositing | |
*/ | |
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { | |
UIImage *image = [self loadImage]; | |
if (image != nil) { | |
CGSize s = image.size; | |
CGRect r = layer.bounds; |
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
/* | |
Source: Apple Developer - Understanding iOS View Compositing | |
Note: setting view.layer.cornerRadius and .masksToBounds | |
sends the view for rending to an offscreen buffer. | |
We want to avoid unnecessary rendering passes. | |
Let the context do the work. | |
*/ | |
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { | |
CGRect rect = layer.bounds; |
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
/* | |
Source: Apple Developer - Understanding iOS View Compositing | |
*/ | |
// setup the layer | |
CALayer *layer = view.layer; | |
layer.bounds = sublayer_bounds; | |
layer.backgroundColor = random_color(); | |
// set the shadow properties on the layer |
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
/* | |
Thanks to @_bejo | |
*/ | |
- (void)_insertGlobalRoomMessage:(id)msg atIndex:(NSUInteger)index | |
{ | |
NSIndexSet *changeSet = [NSIndexSet indexSetWithIndex:index]; | |
[self willChange:NSKeyValueChangeInsertion valuesAtIndexes:changeSet forKey:@"globalRoomMessages"]; | |
[(NSMutableArray *)self.globalRoomMessages insertObject:msg atIndex:index]; | |
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:changeSet forKey:@"globalRoomMessages"]; |
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
# .gitignore in use by Joris Kluivers | |
# | |
# Latest version: | |
# https://gist.github.com/gists/1923197 | |
*.DS_Store | |
# Xcode | |
*.pbxuser | |
*.mode1v3 |
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
// Source: Stanford CS193P November 16, 2010 Lecture 16 | |
// Use case: lots of Core Data changes. You want them to save once they settle down. | |
- (void)delayedSave:(NSManagedObjectContext *)ctxt | |
{ | |
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doSave:) object:ctxt]; | |
[self performSelector:@selector(doSave:) withObject:ctxt afterDelay:1.0]; | |
} |
OlderNewer