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...
View GitHub Profile
@jlcampana
jlcampana / gist:4986979
Created February 19, 2013 15:42
Fecha + timezone
NSTimeInterval timeZoneOffset = [[NSTimeZone defaultTimeZone] secondsFromGMT];
NSDate* today = [[NSDate date] dateByAddingTimeInterval:timeZoneOffset];
@jlcampana
jlcampana / test
Last active December 11, 2015 18:28
Test App GitHub
a ver el timestamp...
@jlcampana
jlcampana / gist:4554634
Created January 17, 2013 08:50
Eliminar celdas vacías al final de una tableview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
//This is just for avoiding separation lines in empty rows (needs "numberOfSectionsInTableView")
if ([self numberOfSectionsInTableView:tableView] == (section+1)){
return [UIView new];
@jlcampana
jlcampana / ScalarIm
Created January 2, 2013 12:09
Escalar imagen
+ (UIImage *)scaleImage:(UIImage *)image ToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@jlcampana
jlcampana / aspect-ratio
Created January 2, 2013 12:01
Cambiar aspect ratio para fotos según pantalla
CGSize s = originalImage.size;
CGSize s2 = [UIScreen mainScreen].bounds.size;
CGSize s3 = CGSizeMake(roundf(s.width / s2.width), roundf(s.height/s2.height));
CGFloat factor = fmax(s3.width, s3.height);
// Divide the size by the greater of the vertical or horizontal shrinkage factor
s.width = roundf(s.width /factor);
s.height = roundf (s.height / factor);
@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
}
@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: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: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 / 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