├── NSArray+ShuffledArray.h ├── NSArray+ShuffledArray.m ├── NSArray+blockFilter.h ├── NSArray+blockFilter.m ├── NSObject+PerformBlock.h ├── NSObject+PerformBlock.m ├── NSValue+CLLocationCoordinate2D.h ├── NSValue+CLLocationCoordinate2D.m ├── README ├── UIColor+ColorFromString.h ├── UIColor+ColorFromString.m ├── UITabBarController_setHidden ├── UITabBarController+HideTabBar.h └── UITabBarController+HideTabBar.m ├── UITextView+RoundedCorners.h ├── UITextView+RoundedCorners.m ├── UIWebView+ContentHeight.h └── UIWebView+ContentHeight.m /NSArray+ShuffledArray.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+ShuffledArray.h 3 | // GuideOne 4 | // 5 | // Created by Carlos Oliva G. on 18-04-11. 6 | // Copyright 2011 iDev Software. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSArray (ShuffledArray) 13 | 14 | - (NSArray *)shuffledArray; 15 | 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /NSArray+ShuffledArray.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+ShuffledArray.m 3 | // GuideOne 4 | // 5 | // Created by Carlos Oliva G. on 18-04-11. 6 | // Copyright 2011 iDev Software. All rights reserved. 7 | // 8 | 9 | #import "NSArray+ShuffledArray.h" 10 | 11 | 12 | @implementation NSArray (ShuffledArray) 13 | 14 | 15 | - (NSArray *)shuffledArray { 16 | return [self sortedArrayUsingComparator:^(id obj1, id obj2) { 17 | return (NSComparisonResult)(arc4random() % 3 - 1); 18 | }]; 19 | } 20 | 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /NSArray+blockFilter.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+blockFilter.h 3 | // ChatTest 4 | // 5 | // Created by Carlos Oliva on 31-07-11. 6 | // Copyright 2011 iDev Software. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (blockFilter) 12 | 13 | - (NSArray *)filteredArrayOfObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))test; 14 | 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /NSArray+blockFilter.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+blockFilter.m 3 | // ChatTest 4 | // 5 | // Created by Carlos Oliva on 31-07-11. 6 | // Copyright 2011 iDev Software. All rights reserved. 7 | // 8 | 9 | #import "NSArray+blockFilter.h" 10 | 11 | @implementation NSArray (blockFilter) 12 | 13 | - (NSArray *)filteredArrayOfObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))test { 14 | NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithCapacity:0]; 15 | for(NSUInteger index = 0; index < [self count]; index++) { 16 | id element = [self objectAtIndex:index]; 17 | BOOL stop = NO; 18 | if(test(element, index, &stop)) { 19 | [mutableArray addObject:element]; 20 | } 21 | if(stop) 22 | break; 23 | } 24 | NSArray *returnArray = [NSArray arrayWithArray:mutableArray]; 25 | [mutableArray release]; 26 | return returnArray; 27 | } 28 | 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /NSObject+PerformBlock.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+PerformBlock.h 3 | // GuideOne 4 | // 5 | // Created by Carlos Oliva G. on 18-04-11. 6 | // Copyright 2011 iDev Software. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSObject (PerformBlock) 13 | 14 | - (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay; 15 | - (void)performBlockInBackground:(void (^)(void))block; 16 | - (void)performBlockOnMainThread:(void (^)(void))block waitUntilDone:(BOOL)wait; 17 | 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /NSObject+PerformBlock.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+PerformBlock.m 3 | // GuideOne 4 | // 5 | // Created by Carlos Oliva G. on 18-04-11. 6 | // Copyright 2011 iDev Software. All rights reserved. 7 | // 8 | // Taken from http://stackoverflow.com/questions/4007023/blocks-instead-of-performselectorwithobjectafterdelay 9 | 10 | #import "NSObject+PerformBlock.h" 11 | 12 | 13 | @implementation NSObject (PerformBlock) 14 | 15 | - (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay { 16 | block = [[block copy] autorelease]; 17 | [self performSelector:@selector(fireBlock:) withObject:block afterDelay:delay]; 18 | } 19 | 20 | 21 | - (void)fireBlock:(void (^)(void))block { 22 | block(); 23 | } 24 | 25 | 26 | - (void)performBlockInBackground:(void (^)(void))block { 27 | block = [[block copy] autorelease]; 28 | [self performSelectorInBackground:@selector(fireBlock:) withObject:block]; 29 | } 30 | 31 | 32 | - (void)performBlockOnMainThread:(void (^)(void))block waitUntilDone:(BOOL)wait { 33 | block = [[block copy] autorelease]; 34 | [self performSelectorOnMainThread:@selector(fireBlock:) withObject:block waitUntilDone:wait]; 35 | } 36 | 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /NSValue+CLLocationCoordinate2D.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSValue+CLLocationCoordinate2D.h 3 | // 4 | // Created by Carlos Oliva G. on 26-04-10. 5 | // Copyright 2010 iDev Software. All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | 12 | @interface NSValue (CLLocationCoordinate2D) 13 | 14 | + (NSValue *)valueWithCLLocationCoordinate2D:(CLLocationCoordinate2D)coordinate; 15 | - (CLLocationCoordinate2D)CLLocationCoordinate2DValue; 16 | 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /NSValue+CLLocationCoordinate2D.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSValue+CLLocationCoordinate2D.m 3 | // 4 | // Created by Carlos Oliva G. on 26-04-10. 5 | // Copyright 2010 iDev Software. All rights reserved. 6 | // 7 | 8 | #import "NSValue+CLLocationCoordinate2D.h" 9 | 10 | @implementation NSValue (CLLocationCoordinate2D) 11 | 12 | 13 | + (NSValue *)valueWithCLLocationCoordinate2D:(CLLocationCoordinate2D)coordinate { 14 | NSValue *value = [[NSValue alloc] initWithBytes:&coordinate 15 | objCType:@encode(CLLocationCoordinate2D)]; 16 | return [value autorelease]; 17 | } 18 | 19 | 20 | - (CLLocationCoordinate2D)CLLocationCoordinate2DValue { 21 | CLLocationCoordinate2D location; 22 | [self getValue:&location]; 23 | return location; 24 | } 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | A collection of assorted categories to common Cocoa Touch classes 2 | 3 | 4 | * UIColor+ColorFromString 5 | 6 | Adds a class method to UIColor for creating UIColor objects from a string 7 | 8 | + (UIColor *)colorFromString:(NSString *)string; 9 | Class method that returns a color object based on the RGBA components 10 | specified as a comma-separated string of decimal (0.0 to 1.0) values, 11 | eg. @"0.5, 0.5, 0.5, 1.0" for 100% opaque gray 12 | 13 | 14 | * UITextView+RoundedCorners 15 | 16 | Adds an instance method to UITextView to toggle rounded corners appearance 17 | 18 | - (void)setRoundedCorners:(BOOL)rounded; 19 | Instance method to specify if the receiver should draw itself with rounded 20 | corners and a border 21 | 22 | 23 | * NSValue+CLLocationCoordinate2D 24 | 25 | Adds methods to NSValue to represent geographical coordinate information 26 | using an NSValue object 27 | 28 | + (NSValue *)valueWithCLLocationCoordinate2D:(CLLocationCoordinate2D)coordinate; 29 | Creates and returns a value object that contains the specified coordinate 30 | structure 31 | 32 | - (CLLocationCoordinate2D)CLLocationCoordinate2DValue 33 | Instance method that returns a coordinate structure representing the data 34 | in the receiver 35 | 36 | 37 | * UIWebView+ContentHeight 38 | 39 | Adds an instance method to UIWebView that returns the height of its content 40 | measured in pixels 41 | 42 | - (CGFloat)contentHeight; 43 | Returns the height of the rendered content for the receiver measured in 44 | pixels 45 | 46 | -------------------------------------------------------------------------------- /UIColor+ColorFromString.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+ColorFromString.h 3 | // 4 | // Created by Carlos Oliva G. on 29-03-10. 5 | // Copyright 2010 iDev Software. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | 11 | @interface UIColor(colorFromString) 12 | 13 | + (UIColor *)colorFromString:(NSString *)string; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /UIColor+ColorFromString.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+ColorFromString.m 3 | // 4 | // Created by Carlos Oliva G. on 29-03-10. 5 | // Copyright 2010 iDev Software. All rights reserved. 6 | // 7 | 8 | #import "UIColor+ColorFromString.h" 9 | 10 | 11 | @implementation UIColor(colorFromString) 12 | 13 | 14 | + (UIColor *)colorFromString:(NSString *)string { 15 | NSArray *colorArray = [string componentsSeparatedByString:@","]; 16 | if([colorArray count] != 4) 17 | return nil; 18 | return [UIColor colorWithRed:[[colorArray objectAtIndex:0] floatValue] 19 | green:[[colorArray objectAtIndex:1] floatValue] 20 | blue:[[colorArray objectAtIndex:2] floatValue] 21 | alpha:[[colorArray objectAtIndex:3] floatValue]]; 22 | } 23 | 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /UITabBarController_setHidden/UITabBarController+HideTabBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITabBarController+HideTabBar.h 3 | // NPS 4 | // 5 | // Created by Carlos Oliva on 04-02-12. 6 | // Copyright (c) 2012 iDev. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITabBarController (HideTabBar) 12 | 13 | @property (nonatomic, getter=isTabBarHidden) BOOL tabBarHidden; 14 | 15 | - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated; 16 | 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /UITabBarController_setHidden/UITabBarController+HideTabBar.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITabBarController+HideTabBar.m 3 | // NPS 4 | // 5 | // Created by Carlos Oliva on 04-02-12. 6 | // Copyright (c) 2012 iDev. All rights reserved. 7 | // 8 | 9 | #import "UITabBarController+HideTabBar.h" 10 | 11 | #define kAnimationDuration .3 12 | 13 | 14 | @implementation UITabBarController (HideTabBar) 15 | 16 | - (BOOL)isTabBarHidden { 17 | CGRect viewFrame = self.view.frame; 18 | CGRect tabBarFrame = self.tabBar.frame; 19 | return tabBarFrame.origin.y >= viewFrame.size.height; 20 | } 21 | 22 | 23 | - (void)setTabBarHidden:(BOOL)hidden { 24 | [self setTabBarHidden:hidden animated:NO]; 25 | } 26 | 27 | 28 | - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated { 29 | BOOL isHidden = self.tabBarHidden; 30 | if(hidden == isHidden) 31 | return; 32 | UIView *transitionView = [[[self.view.subviews reverseObjectEnumerator] allObjects] lastObject]; 33 | if(transitionView == nil) { 34 | NSLog(@"could not get the container view!"); 35 | return; 36 | } 37 | CGRect viewFrame = self.view.frame; 38 | CGRect tabBarFrame = self.tabBar.frame; 39 | CGRect containerFrame = transitionView.frame; 40 | tabBarFrame.origin.y = viewFrame.size.height - (hidden ? 0 : tabBarFrame.size.height); 41 | containerFrame.size.height = viewFrame.size.height - (hidden ? 0 : tabBarFrame.size.height); 42 | [UIView animateWithDuration:kAnimationDuration 43 | animations:^{ 44 | self.tabBar.frame = tabBarFrame; 45 | transitionView.frame = containerFrame; 46 | } 47 | ]; 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /UITextView+RoundedCorners.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+RoundedCorners.h 3 | // 4 | // Created by Carlos Oliva G. on 31-08-10. 5 | // Copyright 2010 iDev Software. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | 11 | @interface UITextView (RoundedCorners) 12 | 13 | - (void)setRoundedCorners:(BOOL)rounded; 14 | 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /UITextView+RoundedCorners.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+RoundedCorners.m 3 | // 4 | // Created by Carlos Oliva G. on 31-08-10. 5 | // Copyright 2010 iDev Software. All rights reserved. 6 | // 7 | 8 | #import 9 | #import "UITextView+RoundedCorners.h" 10 | 11 | 12 | @implementation UITextView (RoundedCorners) 13 | 14 | - (void)setRoundedCorners:(BOOL)rounded { 15 | self.layer.borderWidth = (rounded ? 1 : 0); 16 | self.layer.cornerRadius = (rounded ? 8 : 0); 17 | self.layer.borderColor = [(rounded ? [UIColor grayColor] : [UIColor blackColor]) CGColor]; 18 | } 19 | 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /UIWebView+ContentHeight.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIWebView+ContentHeight.h 3 | // 4 | // Created by Carlos Oliva G. on 10/9/09. 5 | // Copyright 2009 iDev Software. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | 11 | @interface UIWebView (ContentHeight) 12 | 13 | - (CGFloat)contentHeight; 14 | 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /UIWebView+ContentHeight.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIWebView+ContentHeight.m 3 | // 4 | // Created by Carlos Oliva G. on 10/9/09. 5 | // Copyright 2009 iDev Software. All rights reserved. 6 | // 7 | 8 | #import "UIWebView+ContentHeight.h" 9 | 10 | 11 | @implementation UIWebView (ContentHeight) 12 | 13 | - (CGFloat)contentHeight { 14 | return [[self stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight + document.body.offsetTop;"] floatValue]; 15 | } 16 | 17 | 18 | @end 19 | --------------------------------------------------------------------------------