Skip to content

Instantly share code, notes, and snippets.

View jlcampana's full-sized avatar
:octocat:
emu emu emu...

Jose Luis Campaña jlcampana

:octocat:
emu emu emu...
  • Universal Exports
  • Barcelona, España
View GitHub Profile
@jlcampana
jlcampana / gist:3690379
Created September 10, 2012 11:16
Locate the most left non transparent pixel of a UIImage
+ (CGPoint)getMostLeftTransparentPixelOfImage:(UIImage*)image
{
int xx = 0;
int yy = 0;
int count = image.size.width * image.size.height;
// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
@jlcampana
jlcampana / gist:3705738
Created September 12, 2012 10:12
Scroll to a textfield on a table when tapped
//We need some properties
@property (nonatomic,strong) NSMutableArray *dataSource;
@property (nonatomic, strong) UITextField *currentTextField;
@property (nonatomic) CGRect originalTableFrame;
@property (nonatomic) NSIndexPath *indexForCurrentTextField;
@property (nonatomic) NSTimeInterval keyboardAnimationDuration;
//Don't forget to be delegate of UITextFieldDelegate
//Then...
@jlcampana
jlcampana / NSMutableArray+Stack.m
Created September 18, 2012 08:16
NSMutableArray+Stack.m
//
// NSMutableArray+Stack.m
// shell poc
//
// Created by Jose Luis Campaña on 9/18/12.
// Copyright (c) 2012 Jose Luis Campaña. All rights reserved.
//
#import "NSMutableArray+Stack.h"
@jlcampana
jlcampana / NSMutableArray+Stack.h
Created September 18, 2012 08:17
NSMutableArray+Stack.h
//
// NSMutableArray+Stack.h
// shell poc
//
// Created by Jose Luis Campaña on 9/18/12.
// Copyright (c) 2012 Jose Luis Campaña. All rights reserved.
//
#import <Foundation/Foundation.h>
@jlcampana
jlcampana / UIBarButtonItem+Image.m
Created September 18, 2012 08:46
UIBarButtonItem+Image.m
// UIBarButtonItem+Image.m
@implementation UIBarButtonItem (Image)
-(id)initWithImage:(UIImage *)image title:(NSString*)title target:(id)target action:(SEL)action {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.titleLabel.font = [UIFont boldSystemFontOfSize:12];
button.titleLabel.shadowOffset = CGSizeMake(0, -1);
button.titleLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.5];
@jlcampana
jlcampana / UIBarButtonItem+Image.h
Created September 18, 2012 08:47
UIBarButtonItem+Image.h
// UIBarButtonItem+Image.h
@interface UIBarButtonItem (Image)
-(id)initWithImage:(UIImage *)image title:(NSString*)title target:(id)target action:(SEL)action;
@end
@jlcampana
jlcampana / gist:3742910
Created September 18, 2012 12:49
Emulate PIN unlock screen
@property (strong, nonatomic) IBOutlet UITextField *pin1_1;
@property (strong, nonatomic) IBOutlet UITextField *pin1_2;
@property (strong, nonatomic) IBOutlet UITextField *pin1_3;
@property (strong, nonatomic) IBOutlet UITextField *pin1_4;
@property (nonatomic, strong) NSString *pinText;
- (void)viewDidLoad
{
(...)
@jlcampana
jlcampana / gist:3742924
Created September 18, 2012 12:51
Emulate UINavigationController with views
#import "NSMutableArray+Stack.h"
#define SHOW_ANIMATION_DURATON 0.5f
@property (nonatomic, strong) NSMutableArray *viewStack;
-(void)pushView:(UIView *)view
{
UIView *anterior = [self.viewStack peek];
[self.viewStack push:view];
@jlcampana
jlcampana / gist:3863564
Created October 10, 2012 06:50
Imagen a Grayscale
+ (UIImage *)convertImageToGrayScale:(UIImage *)img
{
// Create image rectangle with current image width/height
CGRect imageRect = CGRectMake(0, 0, img.size.width, img.size.height);
// Grayscale color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
// Create bitmap content with current image size and grayscale colorspace
CGContextRef context = CGBitmapContextCreate(nil, img.size.width, img.size.height, 8, 0, colorSpace, kCGImageAlphaNone);
@jlcampana
jlcampana / gist:4130384
Created November 22, 2012 10:11
Lanzar búsqueda mientras escribes
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *newSearch = [textField.text stringByReplacingCharactersInRange:range withString:string];
NSLog(@"%@",newSearch);
if ([newSearch length] >= MIN_NUMBER_OF_CHARACTERS_TO_LAUCH_SEARCH)
{
//Hacer búsqueda con newSearch
}