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:3447423
Created August 24, 2012 08:19
Present a modal view controller with size<screen size
//Assuming the view controller's size is WIDTHxHEIGHT
//Calling the view Controller:
CustomViewController *vc = [[CustomViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:vc animated:YES];
//In the view controller:
-(void)viewWillAppear:(BOOL)animated
{
@jlcampana
jlcampana / gist:3449957
Created August 24, 2012 12:18
Animation
[UIView animateWithDuration:DURATION
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{
}
completion:^(BOOL finished){
}];
@jlcampana
jlcampana / gist:3607635
Created September 3, 2012 07:35
Crear una vista a partir de un XIB
ProductView *v = [[[NSBundle mainBundle] loadNibNamed:@"ProductView" owner:self options:nil] objectAtIndex:0];
@jlcampana
jlcampana / gist:3609629
Created September 3, 2012 14:16
Calcular el ancho de una label
CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:yourLabel.lineBreakMode];
@jlcampana
jlcampana / gist:3618043
Created September 4, 2012 07:37
KVO (ejemplo)
//Vamos a observar la propiedad cartUnits del objeto _product
[_product addObserver:self forKeyPath:@"cartUnits" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if([keyPath isEqualToString:@"cartUnits"])
{
//Acción
}
}
@jlcampana
jlcampana / gist:3618562
Created September 4, 2012 08:35
getRandomIntBetween 2 ints
+(NSInteger)getRandomIntBetween:(NSInteger)min andMax:(NSInteger)max
{
return min + arc4random() % ((max + 1) - min);
}
@jlcampana
jlcampana / gist:3618564
Created September 4, 2012 08:36
Get free memory
+(natural_t) getFreeMemory
{
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {
@jlcampana
jlcampana / gist:3618570
Created September 4, 2012 08:37
Orientation
+(BOOL)orientationIsPortrait
{
return UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]);
}
+ (UIInterfaceOrientation) interfaceOrientation
{
return [[UIApplication sharedApplication] statusBarOrientation];
}
@jlcampana
jlcampana / gist:3618589
Created September 4, 2012 08:39
Time ago
+(NSString *)getTimeAgo:(NSDate *)fecha
{
NSString *timeAgo;
float since_mins,since_hours, since_days, since_months, since_years;
NSTimeInterval since = fabs([fecha timeIntervalSinceNow]);
since_mins = (since / 60);
since_hours = (since_mins / 60);
since_days = (since_hours / 24);
since_months = (since_days / 31);
@jlcampana
jlcampana / gist:3690295
Created September 10, 2012 10:54
Locate first transparent pixel on a UIImage
+ (CGPoint)getFirstTransparentPixelOfImage:(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];