Skip to content

Instantly share code, notes, and snippets.

View jagbolanos's full-sized avatar

Jorge Garcia jagbolanos

View GitHub Profile
@jagbolanos
jagbolanos / gist:3757616
Created September 20, 2012 18:44
Change system font to views
+ (void) setFont:(NSString*)fontName andFactor:(CGFloat)factor toView:(UIView*)view {
NSArray *subviews = view.subviews;
for (NSObject *subview in subviews) {
if ([subview isKindOfClass:[UILabel class]]) {
UILabel *label = (UILabel*)subview;
[label setFont:[UIFont fontWithName:fontName size:label.font.pointSize*factor]];
}
if ([subview isKindOfClass:[UIView class]]) {
[Util setFont:fontName andFactor:factor toView:(UIView*)subview];
}
@jagbolanos
jagbolanos / gist:3725568
Created September 14, 2012 23:22
Binary Tree
data BinaryTree a = BinaryNode a (BinaryTree a) (BinaryTree a) | BinaryNullNode
instance Show a => Show (BinaryTree a) where
show BinaryNullNode = " null"
show (BinaryNode a l r) = " (" ++ show a ++ show l ++ show r ++ ")"
search BinaryNullNode _ = False
search (BinaryNode a l r) v
| v == a = True
| v < a = search l v
@jagbolanos
jagbolanos / gist:3694862
Created September 10, 2012 23:43
Apply an overlay to an image that has alpha only on the visible parts
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
#import <stdlib.h>
- (CGImageRef) createMaskWithImageAlpha: (CGContextRef) originalImageContext {
UInt8 *data = (UInt8 *)CGBitmapContextGetData(originalImageContext);
float width = CGBitmapContextGetBytesPerRow(originalImageContext) / 4;
float height = CGBitmapContextGetHeight(originalImageContext);
@jagbolanos
jagbolanos / gist:3125548
Created July 16, 2012 22:39
Create Unique ID
+ (NSString*) getUniqueID {
CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef newUniqueIdString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueId);
NSString *uniqueId = [NSString stringWithFormat:@"%@",(NSString *)newUniqueIdString];
CFRelease(newUniqueId);
CFRelease(newUniqueIdString);
return [[uniqueId retain] autorelease];
}
@jagbolanos
jagbolanos / gist:3036204
Created July 2, 2012 22:46
Enable search button when empty text
- (void) enableSearchEmpty {
UITextField *searchBarTextField = nil;
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:[UITextField class]])
{
searchBarTextField = (UITextField *)subview;
break;
}
}
@jagbolanos
jagbolanos / gist:3035847
Created July 2, 2012 21:33
searchbar no box
searchBar.barStyle = UIBarStyleBlackTranslucent;
searchBar.backgroundColor = [UIColor clearColor];
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
@jagbolanos
jagbolanos / gist:2975193
Created June 22, 2012 21:02
Check iOS Version
CGFloat systemVersion = [[[ UIDevice currentDevice ] systemVersion ] floatValue ];
if (systemVersion < 5.0) {
} else {
}
@jagbolanos
jagbolanos / gist:2951816
Created June 19, 2012 01:34
Parse ISO8601 Date
+ (NSDate*) parseISO8601DateString:(NSString*)dateString {
ISO8601DateFormatter *formatter = [[ISO8601DateFormatter alloc] init];
formatter.parsesStrictly = YES;
NSDate *date = [formatter dateFromString:dateString];
[formatter release];
return [[date retain] autorelease];
}
@jagbolanos
jagbolanos / gist:2789661
Created May 25, 2012 18:24
Image with borders not affected by resize
progressImage.image = [[UIImage imageNamed:@"black_progress_bar"] resizableImageWithCapInsets:UIEdgeInsetsMake(0., leftCap, 0., leftCap)];
@jagbolanos
jagbolanos / gist:2649319
Created May 9, 2012 22:15
UITextView with Hint Text
- (void) viewDidLoad {
//...
comments.text = @"Comments";
comments.textColor = [UIColor lightGrayColor];
isEmpty = YES;
//...
}
- (BOOL)textViewShouldBeginEditing:(UITextView*)textView {
if (isEmpty) {