Skip to content

Instantly share code, notes, and snippets.

@demigod19892012
demigod19892012 / [iOS] List Files In A Directory And Subdirectories.m
Created April 5, 2013 02:26
[iOS] List Files In A Directory And Subdirectories
NSFileManager *fileMgr;
NSString *entry;
NSString *documentsDir;
NSDirectoryEnumerator *enumerator;
BOOL isDirectory;
// Create file manager
fileMgr = [NSFileManager defaultManager];
// Path to documents directory
@demigod19892012
demigod19892012 / [IOS] Use dispatch_once within GCD.m
Created April 4, 2013 15:06
[IOS] Use dispatch_once within GCD
dispatch_queue_t get_my_background_queue()
{
static dispatch_once_t once;
static dispatch_queue_t my_queue;
dispatch_once(&once, ^{
my_queue = dispatch_queue_create("com.example.background", NULL);
});
return my_queue;
}
@demigod19892012
demigod19892012 / Asset.m
Created April 4, 2013 15:04
[IOS] How to make an image with rounded corners
void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth, float ovalHeight);
{
float fw, fh;
if (ovalWidth == 0 || ovalHeight == 0) {
CGContextAddRect(context, rect);
return;
}
CGContextSaveGState(context);
CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM (context, ovalWidth, ovalHeight);
@demigod19892012
demigod19892012 / [IOS] Correct way to draw background using a pattern image.m
Created April 4, 2013 15:03
[IOS] Correct way to draw background using a pattern image
[[NSGraphicsContext currentContext] saveGraphicsState];
// Change the pattern phase.
[[NSGraphicsContext currentContext] setPatternPhase:
NSMakePoint(0,[self frame].size.height)];
// Stick the image in a color and fill the view with that color.
NSImage *anImage = [NSImage imageNamed:@"bricks"];
[[NSColor colorWithPatternImage:anImage] set];
NSRectFill([self bounds]);
@demigod19892012
demigod19892012 / [IOS] How to capture UIView to UIImage.m
Created April 4, 2013 15:01
[IOS] How to capture UIView to UIImage
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
@demigod19892012
demigod19892012 / [iOS] List Files In A Directory And Subdirectories.m
Created April 4, 2013 14:57
[iOS] List Files In A Directory And Subdirectories
NSFileManager *fileMgr;
NSString *entry;
NSString *documentsDir;
NSDirectoryEnumerator *enumerator;
BOOL isDirectory;
// Create file manager
fileMgr = [NSFileManager defaultManager];
// Path to documents directory
@demigod19892012
demigod19892012 / [iOS] Get All Available Fonts in iOS.m
Created April 4, 2013 14:54
[iOS] Get All Available Fonts in iOS
// Enumerate the installed font family names
[[UIFont familyNames] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
debug(@"\nFamily: %@", obj);
// Enumerate the font names in the each family
[[UIFont fontNamesForFamilyName:obj] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
debug(@"\tFont: %@\n", obj);
}];
@demigod19892012
demigod19892012 / Draw shadow under an UIView.m
Created April 4, 2013 06:58
[IOS] Draw shadow under an UIView
view.layer.masksToBounds = NO;
view.layer.shadowOffset = CGSizeMake(-15, 20);
view.layer.shadowRadius = 5;
view.layer.shadowOpacity = 0.5;
@demigod19892012
demigod19892012 / [IOS]Add swipe back gesture into view.m
Created April 4, 2013 06:54
[IOS]Add swipe back gesture into view
// Add Swipe Gesture Recognizer
- (void)addSwipeBackGesture
{
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
[gesture setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:gesture];
[gesture release];
}
// Handle swipe action
@demigod19892012
demigod19892012 / [IOS]Add swipe back gesture into view.m
Created April 4, 2013 06:51
[IOS]Add swipe back gesture into view
// Add Swipe Gesture Recognizer
- (void)addSwipeBackGesture
{
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
[gesture setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:gesture];
[gesture release];
}
// Handle swipe action